summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGDecl.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2013-07-01 20:22:57 +0000
committerEli Friedman <eli.friedman@gmail.com>2013-07-01 20:22:57 +0000
commit07369dde9d72213bf8a48288cd8b29999af9a40c (patch)
tree233db42fa4864f7c6d6c6ec64d1bbefe8d1acb8e /lib/CodeGen/CGDecl.cpp
parent18a295d96d66c2d99b089882366966e460ed5072 (diff)
downloadclang-07369dde9d72213bf8a48288cd8b29999af9a40c.tar.gz
clang-07369dde9d72213bf8a48288cd8b29999af9a40c.tar.bz2
clang-07369dde9d72213bf8a48288cd8b29999af9a40c.tar.xz
Fix mangling for block literals.
Blocks, like lambdas, can be written in contexts which are required to be treated as the same under ODR. Unlike lambdas, it isn't possible to actually take the address of a block, so the mangling of the block itself doesn't matter. However, objects like static variables inside a block do need to be mangled in a consistent way. There are basically three components here. One, block literals need a consistent numbering. Two, objects/types inside a block literal need to be mangled using it. Three, objects/types inside a block literal need to have their linkage computed correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDecl.cpp')
-rw-r--r--lib/CodeGen/CGDecl.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 519f03aba1..62cd7442ec 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -130,9 +130,27 @@ void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
if (D.isExternallyVisible()) {
const Decl *D = CurCodeDecl;
while (true) {
- if (isa<BlockDecl>(D)) {
- // FIXME: Handle this case properly! (Should be similar to the
- // way we handle lambdas in computeLVForDecl in Decl.cpp.)
+ if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
+ if (!BD->getBlockManglingNumber())
+ break;
+
+ // This block has the linkage/visibility of its contained variables
+ // determined by its owner.
+ const DeclContext *DC = D->getDeclContext()->getRedeclContext();
+ if (Decl *ContextDecl = BD->getBlockManglingContextDecl()) {
+ if (isa<ParmVarDecl>(ContextDecl)) {
+ DC = ContextDecl->getDeclContext()->getRedeclContext();
+ } else {
+ D = ContextDecl;
+ continue;
+ }
+ }
+
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
+ D = ND;
+ continue;
+ }
+
break;
} else if (isa<CapturedDecl>(D)) {
D = cast<Decl>(cast<CapturedDecl>(D)->getParent());
@@ -140,13 +158,26 @@ void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
break;
}
}
- // FIXME: Do we really only care about FunctionDecls here?
+ llvm::GlobalValue::LinkageTypes ParentLinkage;
if (isa<FunctionDecl>(D)) {
- llvm::GlobalValue::LinkageTypes ParentLinkage =
- CGM.getFunctionLinkage(cast<FunctionDecl>(D));
- if (llvm::GlobalValue::isWeakForLinker(ParentLinkage))
- Linkage = ParentLinkage;
+ ParentLinkage = CGM.getFunctionLinkage(cast<FunctionDecl>(D));
+ } else if (isa<VarDecl>(D)) {
+ // FIXME: I'm pretty sure this is wrong...
+ ParentLinkage = CGM.GetLLVMLinkageVarDefinition(cast<VarDecl>(D),
+ /*constant*/false);
+ } else {
+ assert(isa<FieldDecl>(D) && "Expect function, variable, or field");
+ // FIXME: Is this right?
+ ParentLinkage = llvm::GlobalValue::LinkOnceODRLinkage;
}
+
+ if (llvm::GlobalValue::isWeakForLinker(ParentLinkage))
+ Linkage = ParentLinkage;
+
+ // FIXME: We need to force the emission/use of a guard variable for
+ // some variables even if we can constant-evaluate them because
+ // we can't guarantee every translation unit will constant-evaluate them.
+ // Also, we might need to fix up the linkage.
}
return EmitStaticVarDecl(D, Linkage);