diff options
author | Elizabeth Andrews <elizabeth.andrews@intel.com> | 2018-08-22 19:05:19 +0000 |
---|---|---|
committer | Elizabeth Andrews <elizabeth.andrews@intel.com> | 2018-08-22 19:05:19 +0000 |
commit | 6593df241a1d119c84c0d97eec4486d2756c4ea1 (patch) | |
tree | b1d997c87f625efb40506492feb4bafb29aab48d /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | bc6d8970bb6ec44e1a0c8015a803fa382953dfa4 (diff) | |
download | llvm-6593df241a1d119c84c0d97eec4486d2756c4ea1.zip llvm-6593df241a1d119c84c0d97eec4486d2756c4ea1.tar.gz llvm-6593df241a1d119c84c0d97eec4486d2756c4ea1.tar.bz2 |
Currently clang does not emit unused static constants. GCC emits these
constants by default when there is no optimization.
GCC's option -fno-keep-static-consts can be used to not emit
unused static constants.
In Clang, since default behavior does not keep unused static constants,
-fkeep-static-consts can be used to emit these if required. This could be
useful for producing identification strings like SVN identifiers
inside the object file even though the string isn't used by the program.
Differential Revision: https://reviews.llvm.org/D40925
llvm-svn: 340439
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index aaaf6c6..29692ee 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); } |