summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/ItaniumCXXABI.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-12-16 21:00:30 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-12-16 21:00:30 +0000
commitce4757b8e7df547f269b90e5d500714952e8f0b2 (patch)
tree65e2b17d9834e76c91b24ff4db17237e822ff7fe /clang/lib/CodeGen/ItaniumCXXABI.cpp
parent75594b6142c1e7b6d284cf5420c9a06df7723245 (diff)
downloadbcm5719-llvm-ce4757b8e7df547f269b90e5d500714952e8f0b2.tar.gz
bcm5719-llvm-ce4757b8e7df547f269b90e5d500714952e8f0b2.zip
Put static local variables of inline functions in the function comdat.
The variable (and the GV) is only ever used if the function is. Putting it in the function's comdat make it easier for the linker to discard them. The motivating example is struct S { static const int x; }; // const int S::x = 42; inline const int *f() { static const int y = S::x; return &y; } const int *g() { return f(); } With S::x commented out, _ZZ1fvE1y is a variable with a guard variable that is initialized by f. With S::x present, _ZZ1fvE1y is a constant. llvm-svn: 224369
Diffstat (limited to 'clang/lib/CodeGen/ItaniumCXXABI.cpp')
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index fd299d14c13..8d74faf1797 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1711,8 +1711,10 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
// The ABI says: It is suggested that it be emitted in the same COMDAT group
// as the associated data object
- if (!D.isLocalVarDecl() && var->isWeakForLinker() && CGM.supportsCOMDAT()) {
- llvm::Comdat *C = CGM.getModule().getOrInsertComdat(var->getName());
+ if (var->isWeakForLinker() && CGM.supportsCOMDAT()) {
+ StringRef ComdatName =
+ D.isLocalVarDecl() ? CGF.CurFn->getName() : var->getName();
+ llvm::Comdat *C = CGM.getModule().getOrInsertComdat(ComdatName);
guard->setComdat(C);
var->setComdat(C);
CGF.CurFn->setComdat(C);
OpenPOWER on IntegriCloud