bccing cfe-dev, moving the cfe-commits
On 10 March 2014 09:58, Vassil Vassilev <[email protected]> wrote:
> Hi,
> I noticed that CodeGenModule.cpp (around line number 1514):
>
> if (UnnamedAddr)
> Entry->setUnnamedAddr(true);
>
> is executed only in the 'Get'-branch. I.e if the global doesn't exist this
> flag is not taken into account. Is that an inconsistency or a desired
> behavior?
That is a bug, thanks!
For
struct Foo {
~Foo();
};
Foo x;
We will output "@__dso_handle = external global i8", but an
unnamed_addr gets added if a second "Foo y" is added.
John (or Fariborz), can you check if the attached patch is doing the
correct thing for obj-c?
Thanks,
Rafael
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index c8dd813..6946498 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1521,7 +1521,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
}
if (UnnamedAddr)
- Entry->setUnnamedAddr(true);
+ assert(Entry->hasUnnamedAddr());
if (Entry->getType() == Ty)
return Entry;
@@ -1540,6 +1540,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
0, MangledName, 0,
llvm::GlobalVariable::NotThreadLocal, AddrSpace);
+ if(UnnamedAddr)
+ GV->setUnnamedAddr(UnnamedAddr);
+
// This is the first use or definition of a mangled name. If there is a
// deferred decl with this name, remember that we need to emit it at the end
// of the file.
diff --git a/test/CodeGenCXX/global-init2.cpp b/test/CodeGenCXX/global-init2.cpp
new file mode 100644
index 0000000..35cd255
--- /dev/null
+++ b/test/CodeGenCXX/global-init2.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck %s
+
+struct Foo {
+ ~Foo();
+};
+
+Foo x;
+// CHECK: @__dso_handle = external unnamed_addr global i8
diff --git a/test/CodeGenObjC/ns-constant-strings.m b/test/CodeGenObjC/ns-constant-strings.m
index ccaacaf..ae6e248 100644
--- a/test/CodeGenObjC/ns-constant-strings.m
+++ b/test/CodeGenObjC/ns-constant-strings.m
@@ -29,7 +29,7 @@ int main() {
const NSConstantString *appKey1 = @"MyApp1";
}
-// CHECK-FRAGILE: @_NSConstantStringClassReference = external global
+// CHECK-FRAGILE: @_NSConstantStringClassReference = external unnamed_addr global
// CHECK-NONFRAGILE: @"OBJC_CLASS_$_NSConstantString" = external global
// CHECK-FRAGILE: @.str = private unnamed_addr constant [6 x i8] c"MyApp\00"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits