diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 37900bf3ead12..5d1d4f9dc58ee 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -320,6 +320,12 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete ///< template parameter descriptions in ///< forward declarations (versus just ///< including them in the name). +ENUM_CODEGENOPT(DebugSimpleTemplateNames, codegenoptions::DebugTemplateNamesKind, 2, codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template parameters + ///< in the textual names of template + ///< specializations. + ///< Implies DebugFwdTemplateNames to + ///< allow decorated names to be + ///< reconstructed when needed. CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists. CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program diff --git a/clang/include/clang/Basic/DebugInfoOptions.h b/clang/include/clang/Basic/DebugInfoOptions.h index c1259d7797db2..a99a2b5903d7e 100644 --- a/clang/include/clang/Basic/DebugInfoOptions.h +++ b/clang/include/clang/Basic/DebugInfoOptions.h @@ -54,6 +54,12 @@ enum DebugInfoKind { UnusedTypeInfo, }; +enum class DebugTemplateNamesKind { + Full, + Simple, + Mangled +}; + } // end namespace codegenoptions } // end namespace clang diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f0932a0bd1de4..13d740cdb0fb7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2967,6 +2967,15 @@ def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group, HelpText<"Set DWARF fission mode to either 'split' or 'single'">, Values<"split,single">; def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group; +def gsimple_template_names : Flag<["-"], "gsimple-template-names">, Group; +def gsimple_template_names_EQ + : Joined<["-"], "gsimple-template-names=">, + Group, + HelpText<"Use simple template names in DWARF, or include the full " + "template name with a modified prefix for validation">, + Values<"simple,mangled">, Flags<[CC1Option]>; +def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">, + Group; def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, Flags<[CC1Option]>; def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group; def gpubnames : Flag<["-"], "gpubnames">, Group, Flags<[CC1Option]>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index e6742c6575b9f..6c7b8bbcaad79 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4128,6 +4128,29 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, options::OPT_gpubnames) ? "-gpubnames" : "-ggnu-pubnames"); + const auto *SimpleTemplateNamesArg = + Args.getLastArg(options::OPT_gsimple_template_names, options::OPT_gno_simple_template_names, + options::OPT_gsimple_template_names_EQ); + bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE; + if (SimpleTemplateNamesArg && + checkDebugInfoOption(SimpleTemplateNamesArg, Args, D, TC)) { + const auto &Opt = SimpleTemplateNamesArg->getOption(); + if (Opt.matches(options::OPT_gsimple_template_names)) { + ForwardTemplateParams = true; + CmdArgs.push_back("-gsimple-template-names=simple"); + } else if (Opt.matches(options::OPT_gsimple_template_names_EQ)) { + ForwardTemplateParams = true; + StringRef Value = SimpleTemplateNamesArg->getValue(); + if (Value == "simple") { + CmdArgs.push_back("-gsimple-template-names=simple"); + } else if (Value == "mangled") { + CmdArgs.push_back("-gsimple-template-names=mangled"); + } else { + D.Diag(diag::err_drv_unsupported_option_argument) + << Opt.getName() << SimpleTemplateNamesArg->getValue(); + } + } + } if (Args.hasFlag(options::OPT_fdebug_ranges_base_address, options::OPT_fno_debug_ranges_base_address, false)) { @@ -4174,7 +4197,7 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, // Decide how to render forward declarations of template instantiations. // SCE wants full descriptions, others just get them in the name. - if (DebuggerTuning == llvm::DebuggerKind::SCE) + if (ForwardTemplateParams) CmdArgs.push_back("-debug-forward-template-params"); // Do we need to explicitly import anonymous namespaces into the parent diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 10b2e96e89578..2368e68841883 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1411,6 +1411,14 @@ void CompilerInvocation::GenerateCodeGenArgs( llvm::DICompileUnit::DebugNameTableKind::Default)) GenerateArg(Args, OPT_gpubnames, SA); + auto TNK = Opts.getDebugSimpleTemplateNames(); + if (TNK != codegenoptions::DebugTemplateNamesKind::Full) { + if (TNK == codegenoptions::DebugTemplateNamesKind::Simple) + GenerateArg(Args, OPT_gsimple_template_names_EQ, "simple", SA); + if (TNK == codegenoptions::DebugTemplateNamesKind::Mangled) + GenerateArg(Args, OPT_gsimple_template_names_EQ, "mangled", SA); + + } // ProfileInstrumentUsePath is marshalled automatically, no need to generate // it or PGOUseInstrumentor. @@ -1685,6 +1693,12 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, : Args.hasArg(OPT_gpubnames) ? llvm::DICompileUnit::DebugNameTableKind::Default : llvm::DICompileUnit::DebugNameTableKind::None); + if (const Arg *A = Args.getLastArg(OPT_gsimple_template_names_EQ)) { + Opts.setDebugSimpleTemplateNames( + StringRef(A->getValue()) == "simple" + ? codegenoptions::DebugTemplateNamesKind::Simple + : codegenoptions::DebugTemplateNamesKind::Mangled); + } if (!Opts.ProfileInstrumentUsePath.empty()) setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath); diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index 4bf2c202dacf1..5f652cb49b71b 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -435,3 +435,15 @@ // DIRECTORY-NOT: "-fno-dwarf-directory-asm" // NODIRECTORY: "-fno-dwarf-directory-asm" + +// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_NAMES %s +// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=simple %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_NAMES %s +// SIMPLE_TEMP_NAMES: -gsimple-template-names=simple +// SIMPLE_TEMP_NAMES: -debug-forward-template-params +// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=mangled %s 2>&1 | FileCheck --check-prefix=MANGLED_TEMP_NAMES %s +// MANGLED_TEMP_NAMES: -gsimple-template-names=mangled +// MANGLED_TEMP_NAMES: -debug-forward-template-params +// RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s +// FULL_TEMP_NAMES-NOT: -gsimple-template-names +// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=other %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_OTHER %s +// SIMPLE_TEMP_OTHER: error: unsupported argument 'other' to option 'gsimple-template-names='