[llvm-branch-commits] [cfe-branch] r118073 - in /cfe/branches/Apple/whitney: lib/CodeGen/CGDecl.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/visibility.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 2 14:35:22 PDT 2010
Author: ddunbar
Date: Tue Nov 2 16:35:21 2010
New Revision: 118073
URL: http://llvm.org/viewvc/llvm-project?rev=118073&view=rev
Log:
Merge r118065:
--
Author: John McCall <rjmccall at apple.com>
Date: Tue Nov 2 21:04:24 2010 +0000
Ensure that static local variables in function templates inherit the
visibility of their function.
Modified:
cfe/branches/Apple/whitney/lib/CodeGen/CGDecl.cpp
cfe/branches/Apple/whitney/lib/CodeGen/CodeGenModule.cpp
cfe/branches/Apple/whitney/lib/CodeGen/ItaniumCXXABI.cpp
cfe/branches/Apple/whitney/test/CodeGenCXX/visibility.cpp
Modified: cfe/branches/Apple/whitney/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/CodeGen/CGDecl.cpp?rev=118073&r1=118072&r2=118073&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/branches/Apple/whitney/lib/CodeGen/CGDecl.cpp Tue Nov 2 16:35:21 2010
@@ -172,6 +172,8 @@
CGM.EmitNullConstant(D.getType()), Name, 0,
D.isThreadSpecified(), Ty.getAddressSpace());
GV->setAlignment(getContext().getDeclAlign(&D).getQuantity());
+ if (Linkage != llvm::GlobalValue::InternalLinkage)
+ GV->setVisibility(CurFn->getVisibility());
return GV;
}
@@ -209,8 +211,10 @@
GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
OldGV->isConstant(),
OldGV->getLinkage(), Init, "",
- 0, D.isThreadSpecified(),
+ /*InsertBefore*/ OldGV,
+ D.isThreadSpecified(),
D.getType().getAddressSpace());
+ GV->setVisibility(OldGV->getVisibility());
// Steal the name of the old global
GV->takeName(OldGV);
Modified: cfe/branches/Apple/whitney/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/CodeGen/CodeGenModule.cpp?rev=118073&r1=118072&r2=118073&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/branches/Apple/whitney/lib/CodeGen/CodeGenModule.cpp Tue Nov 2 16:35:21 2010
@@ -1344,9 +1344,16 @@
Entry = NewFn;
}
+ // We need to set linkage and visibility on the function before
+ // generating code for it because various parts of IR generation
+ // want to propagate this information down (e.g. to local static
+ // declarations).
llvm::Function *Fn = cast<llvm::Function>(Entry);
setFunctionLinkage(D, Fn);
+ // FIXME: this is redundant with part of SetFunctionDefinitionAttributes
+ setGlobalVisibility(Fn, D, /*ForDef*/ true);
+
CodeGenFunction(*this).GenerateCode(D, Fn);
SetFunctionDefinitionAttributes(D, Fn);
Modified: cfe/branches/Apple/whitney/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/CodeGen/ItaniumCXXABI.cpp?rev=118073&r1=118072&r2=118073&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/branches/Apple/whitney/lib/CodeGen/ItaniumCXXABI.cpp Tue Nov 2 16:35:21 2010
@@ -1092,6 +1092,9 @@
// Create the guard variable.
llvm::SmallString<256> GuardVName;
getMangleContext().mangleItaniumGuardVariable(&D, GuardVName);
+
+ // FIXME: we should just absorb linkage and visibility from the
+ // variable, but that's not always set up properly just yet.
llvm::GlobalValue::LinkageTypes Linkage = GV->getLinkage();
if (D.isStaticDataMember() &&
D.getInstantiatedFromStaticDataMember())
@@ -1102,6 +1105,7 @@
false, Linkage,
llvm::ConstantInt::get(GuardTy, 0),
GuardVName.str());
+ GuardVariable->setVisibility(GV->getVisibility());
// Test whether the variable has completed initialization.
llvm::Value *IsInitialized;
Modified: cfe/branches/Apple/whitney/test/CodeGenCXX/visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/CodeGenCXX/visibility.cpp?rev=118073&r1=118072&r2=118073&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/CodeGenCXX/visibility.cpp (original)
+++ cfe/branches/Apple/whitney/test/CodeGenCXX/visibility.cpp Tue Nov 2 16:35:21 2010
@@ -22,6 +22,10 @@
// CHECK-HIDDEN: @_ZN6Test143varE = external global
// CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
// CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
+// CHECK: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr global
+// CHECK: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr global i64
+// CHECK-HIDDEN: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr hidden global
+// CHECK-HIDDEN: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr hidden global i64
// CHECK-HIDDEN: @_ZTTN6Test161AIcEE = external constant
// CHECK-HIDDEN: @_ZTVN6Test161AIcEE = external constant
// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant
@@ -250,3 +254,16 @@
a.foo();
}
}
+
+namespace Test19 {
+ struct A { A(); ~A(); };
+
+ // Tested at top of file.
+ template <class T> void foo() {
+ static A a;
+ }
+
+ void test() {
+ foo<int>();
+ }
+}
More information about the llvm-branch-commits
mailing list