summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index aaaf6c6d754..29692eedb53 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1350,6 +1350,12 @@ void CodeGenModule::SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV) {
if (D && D->hasAttr<UsedAttr>())
addUsedGlobal(GV);
+
+ if (CodeGenOpts.KeepStaticConsts && D && isa<VarDecl>(D)) {
+ const auto *VD = cast<VarDecl>(D);
+ if (VD->getType().isConstQualified() && VD->getStorageClass() == SC_Static)
+ addUsedGlobal(GV);
+ }
}
bool CodeGenModule::GetCPUAndFeaturesAttributes(const Decl *D,
@@ -1985,6 +1991,13 @@ bool CodeGenModule::MustBeEmitted(const ValueDecl *Global) {
if (LangOpts.EmitAllDecls)
return true;
+ if (CodeGenOpts.KeepStaticConsts) {
+ const auto *VD = dyn_cast<VarDecl>(Global);
+ if (VD && VD->getType().isConstQualified() &&
+ VD->getStorageClass() == SC_Static)
+ return true;
+ }
+
return getContext().DeclMustBeEmitted(Global);
}
OpenPOWER on IntegriCloud