From 53b59bc2474592d8f536333bae403e266ddda2e6 Mon Sep 17 00:00:00 2001 From: Mikhail Maltsev Date: Mon, 23 Apr 2018 10:08:46 +0000 Subject: [PATCH] [CodeGen] Reland r330442: Add an option to suppress output of llvm.ident The test case in the original patch was overly contrained and failed on PPC targets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330575 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 5 ++++- include/clang/Frontend/CodeGenOptions.def | 1 + lib/CodeGen/CGDebugInfo.cpp | 3 ++- lib/CodeGen/CodeGenModule.cpp | 3 ++- lib/Driver/ToolChains/Clang.cpp | 3 +++ lib/Frontend/CompilerInvocation.cpp | 2 ++ test/CodeGen/no-ident-version.c | 19 +++++++++++++++++++ 7 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/no-ident-version.c diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index c97324441b..e3ced42154 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -396,7 +396,10 @@ def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["2"]>; def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>; def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group, HelpText<"Disable linemarker output in -E mode">; -def Qn : Flag<["-"], "Qn">, IgnoredGCCCompat; +def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>, + HelpText<"Emit metadata containing compiler name and version">; +def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>, + HelpText<"Do not emit metadata containing compiler name and version">; def Qunused_arguments : Flag<["-"], "Qunused-arguments">, Flags<[DriverOption, CoreOption]>, HelpText<"Don't emit warning for unused driver arguments">; def Q : Flag<["-"], "Q">, IgnoredGCCCompat; diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 684f99e1de..1684dbdb55 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -69,6 +69,7 @@ CODEGENOPT(EmitDeclMetadata , 1, 0) ///< Emit special metadata indicating what ///< Decl* various IR entities came from. ///< Only useful when running CodeGen as a ///< subroutine. +CODEGENOPT(EmitVersionIdentMetadata , 1, 1) ///< Emit compiler version metadata. CODEGENOPT(EmitGcovArcs , 1, 0) ///< Emit coverage data files, aka. GCDA. CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO. CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata. diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index bdd326d70e..474018c065 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -577,7 +577,8 @@ void CGDebugInfo::CreateCompileUnit() { remapDIPath(getCurrentDirname()), CSInfo, getSource(SM, SM.getMainFileID())), - Producer, LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex, + CGOpts.EmitVersionIdentMetadata ? Producer : "", + LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex, CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind, 0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling, diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 63fcc8fbce..063b9be4cd 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -571,7 +571,8 @@ void CodeGenModule::Release() { if (DebugInfo) DebugInfo->finalize(); - EmitVersionIdentMetadata(); + if (getCodeGenOpts().EmitVersionIdentMetadata) + EmitVersionIdentMetadata(); EmitTargetMetadata(); } diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index a3cb0f21ed..6c5e2caae4 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -4408,6 +4408,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } + if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn, true)) + CmdArgs.push_back("-Qn"); + // -fcommon is the default unless compiling kernel code or the target says so bool NoCommonDefault = KernelOrKext || isNoCommonDefault(RawTriple); if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 67e15b41ad..f904e65e72 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1112,6 +1112,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.EmitCheckPathComponentsToStrip = getLastArgIntValue( Args, OPT_fsanitize_undefined_strip_path_components_EQ, 0, Diags); + Opts.EmitVersionIdentMetadata = Args.hasFlag(OPT_Qy, OPT_Qn, true); + return Success; } diff --git a/test/CodeGen/no-ident-version.c b/test/CodeGen/no-ident-version.c new file mode 100644 index 0000000000..ad2a7db2d3 --- /dev/null +++ b/test/CodeGen/no-ident-version.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -o - %s \ +// RUN: | FileCheck --check-prefix=CHECK-NONE %s +// RUN: %clang_cc1 -Qn -emit-llvm -debug-info-kind=limited -o - %s \ +// RUN: | FileCheck --check-prefix=CHECK-QN %s +// RUN: %clang_cc1 -Qy -emit-llvm -debug-info-kind=limited -o - %s \ +// RUN: | FileCheck --check-prefix=CHECK-QY %s + +// CHECK-NONE: @main +// CHECK-NONE: llvm.ident +// CHECK-NONE: producer: + +// CHECK-QN: @main +// CHECK-QN-NOT: llvm.ident +// CHECK-QN-NOT: producer: + +// CHECK-QY: @main +// CHECK-QY: llvm.ident +// CHECK-QY: producer: +int main(void) {} -- 2.40.0