summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp9
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h3
-rw-r--r--clang/test/CodeGenCXX/global-init.cpp1
-rw-r--r--clang/test/CodeGenObjC/constant-string-class.m1
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
OpenPOWER on IntegriCloud