[PATCH] D52659: [LLVM-C] Add an accessor for the "value type" of a global

Robert Widmann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 28 09:24:45 PDT 2018


CodaFi created this revision.
CodaFi added reviewers: whitequark, deadalnix.
Herald added a subscriber: llvm-commits.

Before this, there was no reasonable way to retrieve the type a global value (most notable, a function) was created with from the C API.


Repository:
  rL LLVM

https://reviews.llvm.org/D52659

Files:
  include/llvm-c/Core.h
  lib/IR/Core.cpp


Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -1876,6 +1876,10 @@
                      : GlobalValue::UnnamedAddr::None);
 }
 
+LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global) {
+  return wrap(unwrap<GlobalValue>(Global)->getValueType());
+}
+
 /*--.. Operations on global variables, load and store instructions .........--*/
 
 unsigned LLVMGetAlignment(LLVMValueRef V) {
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -2104,6 +2104,14 @@
 LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
 void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
 
+/**
+ * Returns the "value type" of a global value.  This differs from the formal
+ * type of a global value which is always a pointer type.
+ *
+ * @see llvm::GlobalValue::getValueType()
+ */
+LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
+
 /** Deprecated: Use LLVMGetUnnamedAddress instead. */
 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
 /** Deprecated: Use LLVMSetUnnamedAddress instead. */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52659.167500.patch
Type: text/x-patch
Size: 1199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180928/5ff11926/attachment.bin>


More information about the llvm-commits mailing list