diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 7 | ||||
-rw-r--r-- | clang/lib/CodeGen/ItaniumCXXABI.cpp | 4 |
3 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index e381e979470..5ac8508375f 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -172,6 +172,8 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, 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 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, 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); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d975a22643c..a2b80bea6c0 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1344,9 +1344,16 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD) { 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); diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index b6c40b64db2..94c1f60a8b2 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1092,6 +1092,9 @@ void ItaniumCXXABI::EmitStaticLocalInit(CodeGenFunction &CGF, // 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 @@ void ItaniumCXXABI::EmitStaticLocalInit(CodeGenFunction &CGF, false, Linkage, llvm::ConstantInt::get(GuardTy, 0), GuardVName.str()); + GuardVariable->setVisibility(GV->getVisibility()); // Test whether the variable has completed initialization. llvm::Value *IsInitialized; |