diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-18 21:07:57 +0000 | 
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-18 21:07:57 +0000 | 
| commit | d661a853fd3da74eff3525ea3c3af1cae831db3e (patch) | |
| tree | a4c33a387dff1d8e41cf409df04216a84c22e7cc | |
| parent | e6290ccf9b56dec24e3821eec1a3fb034b1bc0a8 (diff) | |
| download | bcm5719-llvm-d661a853fd3da74eff3525ea3c3af1cae831db3e.tar.gz bcm5719-llvm-d661a853fd3da74eff3525ea3c3af1cae831db3e.zip  | |
Add unnamed_addr in CreateRuntimeVariable.
llvm-svn: 123773
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 3 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/global-init.cpp | 1 | ||||
| -rw-r--r-- | clang/test/CodeGenObjC/constant-string-class.m | 1 | 
4 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 42d5e7923f0..4d0d40a0a8e 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -922,7 +922,8 @@ static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) {  llvm::Constant *  CodeGenModule::GetOrCreateLLVMGlobal(llvm::StringRef MangledName,                                       const llvm::PointerType *Ty, -                                     const VarDecl *D) { +                                     const VarDecl *D, +                                     bool UnnamedAddr) {    // Lookup the entry, lazily creating it if necessary.    llvm::GlobalValue *Entry = GetGlobalValue(MangledName);    if (Entry) { @@ -933,6 +934,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(llvm::StringRef MangledName,        WeakRefReferences.erase(Entry);      } +    if (UnnamedAddr) +      Entry->setUnnamedAddr(true); +      if (Entry->getType() == Ty)        return Entry; @@ -1008,7 +1012,8 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,  llvm::Constant *  CodeGenModule::CreateRuntimeVariable(const llvm::Type *Ty,                                       llvm::StringRef Name) { -  return GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), 0); +  return GetOrCreateLLVMGlobal(Name,  llvm::PointerType::getUnqual(Ty), 0, +                               true);  }  void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) { diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index b1395be8c54..55674ba6a6a 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -519,7 +519,8 @@ private:                                            GlobalDecl D);    llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName,                                          const llvm::PointerType *PTy, -                                        const VarDecl *D); +                                        const VarDecl *D, +                                        bool UnnamedAddr = false);    /// SetCommonAttributes - Set attributes which are common to any    /// form of a global definition (alias, Objective-C method, diff --git a/clang/test/CodeGenCXX/global-init.cpp b/clang/test/CodeGenCXX/global-init.cpp index f89e9781319..60032708168 100644 --- a/clang/test/CodeGenCXX/global-init.cpp +++ b/clang/test/CodeGenCXX/global-init.cpp @@ -12,6 +12,7 @@ struct C { void *field; };  struct D { ~D(); }; +// CHECK: @__dso_handle = external unnamed_addr global i8*  // CHECK: @c = global %struct.C zeroinitializer, align 8  // It's okay if we ever implement the IR-generation optimization to remove this. diff --git a/clang/test/CodeGenObjC/constant-string-class.m b/clang/test/CodeGenObjC/constant-string-class.m index 3d182384a2e..12253d6c70f 100644 --- a/clang/test/CodeGenObjC/constant-string-class.m +++ b/clang/test/CodeGenObjC/constant-string-class.m @@ -32,3 +32,4 @@ int main () {  // CHECK-FRAGILE: @_FooClassReference = common global  // CHECK-NONFRAGILE: @"OBJC_CLASS_$_Object" = external global +// CHECK-NONFRAGILE: "OBJC_CLASS_$_Foo" = unnamed_addr global  | 

