Add a flag to Module::getGlobalVariable to allow it to return vars with
authorChris Lattner <sabre@nondot.org>
Mon, 5 Dec 2005 05:30:21 +0000 (05:30 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 Dec 2005 05:30:21 +0000 (05:30 +0000)
internal linkage.

Patch provided by Evan Jones, thanks!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24604 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/VMCore/Module.cpp

index 1ee8750eca461bbfe2507a0d55f74173cd54d1b5..da2b53ddb5b48a64351e24cd65a3fab3d3851f9e 100644 (file)
@@ -137,13 +137,14 @@ public:
   //
 
   /// getGlobalVariable - Look up the specified global variable in the module
-  /// symbol table.  If it does not exist, return null.  Note that this only
-  /// returns a global variable if it does not have internal linkage.  The type
-  /// argument should be the underlying type of the global, i.e., it should not
-  /// have the top-level PointerType, which represents the address of the
-  /// global.
+  /// symbol table.  If it does not exist, return null.  The type argument
+  /// should be the underlying type of the global, i.e., it should not have
+  /// the top-level PointerType, which represents the address of the global.
+  /// If AllowInternal is set to true, this function will return types that
+  /// have InternalLinkage. By default, these types are not returned.
   ///
-  GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty);
+  GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty,
+                                    bool AllowInternal = false);
 
 
   //===--------------------------------------------------------------------===//
index a554d8e092444e043bc802eebd9fa305c9743037..de63b4baa70a4014c7a60ad96d78ddd62d856d76 100644 (file)
@@ -206,17 +206,17 @@ Function *Module::getNamedFunction(const std::string &Name) {
 //
 
 /// getGlobalVariable - Look up the specified global variable in the module
-/// symbol table.  If it does not exist, return null.  Note that this only
-/// returns a global variable if it does not have internal linkage.  The type
-/// argument should be the underlying type of the global, ie, it should not
-/// have the top-level PointerType, which represents the address of the
-/// global.
+/// symbol table.  If it does not exist, return null.  The type argument
+/// should be the underlying type of the global, i.e., it should not have
+/// the top-level PointerType, which represents the address of the global.
+/// If AllowInternal is set to true, this function will return types that
+/// have InternalLinkage. By default, these types are not returned.
 ///
 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
-                                          const Type *Ty) {
+                                          const Type *Ty, bool AllowInternal) {
   if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) {
     GlobalVariable *Result = cast<GlobalVariable>(V);
-    if (!Result->hasInternalLinkage())
+    if (AllowInternal || !Result->hasInternalLinkage())
       return Result;
   }
   return 0;