From: Rafael Espindola Date: Tue, 18 Jan 2011 21:07:57 +0000 (+0000) Subject: Add unnamed_addr in CreateRuntimeVariable. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c532b502858032f377056dc8cba2fe43cba8702b;p=clang Add unnamed_addr in CreateRuntimeVariable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123773 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 42d5e7923f..4d0d40a0a8 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/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/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index b1395be8c5..55674ba6a6 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/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/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp index f89e978131..6003270816 100644 --- a/test/CodeGenCXX/global-init.cpp +++ b/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/test/CodeGenObjC/constant-string-class.m b/test/CodeGenObjC/constant-string-class.m index 3d182384a2..12253d6c70 100644 --- a/test/CodeGenObjC/constant-string-class.m +++ b/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