diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-05 05:20:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-05 05:20:29 +0000 |
commit | f49573d1eedcf1e44893d5a062ac1b72c8419646 (patch) | |
tree | 8deba03bd2238a546749d2d48c95aaadec3ce25f /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | c0693bc2ea90baa6c3abe3f00c42a4dbf819916b (diff) | |
download | bcm5719-llvm-f49573d1eedcf1e44893d5a062ac1b72c8419646.tar.gz bcm5719-llvm-f49573d1eedcf1e44893d5a062ac1b72c8419646.zip |
weak globals that are const should get weak_odr linkage.
add a fixme about C++ const.
llvm-svn: 78159
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 95ce3e5d3af..df1781de9ec 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -870,7 +870,15 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { } GV->setInitializer(Init); - GV->setConstant(D->getType().isConstant(Context)); + + // If it is safe to mark the global 'constant', do so now. + GV->setConstant(false); + if (D->getType().isConstant(Context)) { + // FIXME: In C++, if the variable has a non-trivial ctor/dtor or any mutable + // members, it cannot be declared "LLVM const". + GV->setConstant(true); + } + GV->setAlignment(getContext().getDeclAlignInBytes(D)); // Set the llvm linkage type as appropriate. @@ -880,13 +888,18 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { GV->setLinkage(llvm::Function::DLLImportLinkage); else if (D->hasAttr<DLLExportAttr>()) GV->setLinkage(llvm::Function::DLLExportLinkage); - else if (D->hasAttr<WeakAttr>()) - GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); - else if (!CompileOpts.NoCommon && + else if (D->hasAttr<WeakAttr>()) { + if (GV->isConstant()) + GV->setLinkage(llvm::GlobalVariable::WeakODRLinkage); + else + GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); + } else if (!CompileOpts.NoCommon && !D->hasExternalStorage() && !D->getInit() && - !D->getAttr<SectionAttr>()) + !D->getAttr<SectionAttr>()) { GV->setLinkage(llvm::GlobalVariable::CommonLinkage); - else + // common vars aren't constant even if declared const. + GV->setConstant(false); + } else GV->setLinkage(llvm::GlobalVariable::ExternalLinkage); SetCommonAttributes(D, GV); |