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 | |
| parent | bc6d8970bb6ec44e1a0c8015a803fa382953dfa4 (diff) | |
| download | bcm5719-llvm-6593df241a1d119c84c0d97eec4486d2756c4ea1.tar.gz bcm5719-llvm-6593df241a1d119c84c0d97eec4486d2756c4ea1.zip | |
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')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 |
3 files changed, 16 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); } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 135d40fc700..45c63d54301 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4008,6 +4008,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, options::OPT_fno_emulated_tls); + Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts); // AltiVec-like language extensions aren't relevant for assembling. if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 8e836b163ef..78ed8f78207 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1145,6 +1145,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, << A->getAsString(Args) << A->getValue(); } + Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts); + return Success; } |

