summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/ItaniumCXXABI.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-09-18 23:41:44 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-09-18 23:41:44 +0000
commitc0ce9eca0b709b16e9c1d0f1686d4e2314af02b8 (patch)
tree71ed27a2daa450a3c47f64aac713d573e5751d7c /clang/lib/CodeGen/ItaniumCXXABI.cpp
parent2ea8639696ce7f3f732cc2f3607a1aa794eca86f (diff)
downloadbcm5719-llvm-c0ce9eca0b709b16e9c1d0f1686d4e2314af02b8.tar.gz
bcm5719-llvm-c0ce9eca0b709b16e9c1d0f1686d4e2314af02b8.zip
Put more stuff in the comdat used for variables with static init.
Clang can already handle ------------------------------------------- struct S { static const int x; }; template<typename T> struct U { static const int k; }; template<typename T> const int U<T>::k = T::x; const int S::x = 42; extern const int *f(); const int *g() { return &U<S>::k; } int main() { return *f() + U<S>::k; } const int *f() { return &U<S>::k; } ------------------------------------------- since r217264 which puts the .inint_array section in the same COMDAT as the variable. This patch allows the linker to more easily delete some dead code and data by putting the guard variable and init function in the same COMDAT. llvm-svn: 218089
Diffstat (limited to 'clang/lib/CodeGen/ItaniumCXXABI.cpp')
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 4a24e77139f..865831fedac 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1666,6 +1666,13 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
// If the variable is thread-local, so is its guard variable.
guard->setThreadLocalMode(var->getThreadLocalMode());
+ // The ABI says: It is suggested that it be emitted in the same COMDAT group
+ // as the associated data object
+ if (var->isWeakForLinker() && CGM.supportsCOMDAT()) {
+ llvm::Comdat *C = CGM.getModule().getOrInsertComdat(var->getName());
+ guard->setComdat(C);
+ }
+
CGM.setStaticLocalDeclGuardAddress(&D, guard);
}
OpenPOWER on IntegriCloud