[clang] 38c09ea - DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 23 07:12:21 PDT 2021


Resending to cfe-commits instead of llvm-commits (doh!).

> -----Original Message-----
> From: Robinson, Paul
> Sent: Thursday, September 23, 2021 10:05 AM
> To: David Blaikie <dblaikie at gmail.com>; 'llvm-commits at lists.llvm.org'
> <llvm-commits at lists.llvm.org>
> Cc: Adrian Prantl <aprantl at apple.com>; Jonas Devlieghere
> <jdevlieghere at apple.com>
> Subject: RE: [clang] 38c09ea - DebugInfo: Add (initially no-op) -gsimple-
> template-names={simple,mangled}
> 
> -gsimple-template-names=mangled seems like a testing feature?
> That would be parseable only by llvm-dwarfdump...
> In which case it seems like it should be a -cc1 option not a
> driver option.
> --paulr
> 
> > -----Original Message-----
> > From: cfe-commits <cfe-commits-bounces at lists.llvm.org> On Behalf Of
> David
> > Blaikie via cfe-commits
> > Sent: Wednesday, September 22, 2021 2:12 PM
> > To: cfe-commits at lists.llvm.org
> > Subject: [clang] 38c09ea - DebugInfo: Add (initially no-op) -gsimple-
> > template-names={simple,mangled}
> >
> >
> > Author: David Blaikie
> > Date: 2021-09-22T11:11:49-07:00
> > New Revision: 38c09ea2d279eddddabe3602e2002f8cdfcc5380
> >
> > URL: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> >
> project/commit/38c09ea2d279eddddabe3602e2002f8cdfcc5380__;!!JmoZiZGBv3RvKR
> > Sx!sx4rLw3CFwdj-rfDEK1Ah3HnANZSLOpXYFIcie1Oiyili8LKwFHxFk-g0F7-Z2pXAg$
> > DIFF: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> >
> project/commit/38c09ea2d279eddddabe3602e2002f8cdfcc5380.diff__;!!JmoZiZGBv
> > 3RvKRSx!sx4rLw3CFwdj-rfDEK1Ah3HnANZSLOpXYFIcie1Oiyili8LKwFHxFk-
> > g0F4WQP9bxA$
> >
> > LOG: DebugInfo: Add (initially no-op) -gsimple-template-
> > names={simple,mangled}
> >
> > This is to build the foundation of a new debug info feature to use only
> > the base name of template as its debug info name (eg: "t1" instead of
> > the full "t1<int>"). The intent being that a consumer can still retrieve
> > all that information from the DW_TAG_template_*_parameters.
> >
> > So gno-simple-template-names is business as usual/previously ("t1<int>")
> >    =simple is the simplified name ("t1")
> >    =mangled is a special mode to communicate the full information, but
> >    also indicate that the name should be able to be simplified. The data
> >    is encoded as "_STNt1|<int>" which will be matched with an
> >    llvm-dwarfdump --verify feature to deconstruct this name, rebuild the
> >    original name, and then try to rebuild the simple name via the DWARF
> >    tags - then compare the latter and the former to ensure that all the
> >    data necessary to fully rebuild the name is present.
> >
> > Added:
> >
> >
> > Modified:
> >     clang/include/clang/Basic/CodeGenOptions.def
> >     clang/include/clang/Basic/DebugInfoOptions.h
> >     clang/include/clang/Driver/Options.td
> >     clang/lib/Driver/ToolChains/Clang.cpp
> >     clang/lib/Frontend/CompilerInvocation.cpp
> >     clang/test/Driver/debug-options.c
> >
> > Removed:
> >
> >
> >
> >
> ##########################################################################
> > ######
> > diff  --git a/clang/include/clang/Basic/CodeGenOptions.def
> > b/clang/include/clang/Basic/CodeGenOptions.def
> > index 37900bf3ead1..5d1d4f9dc58e 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 c1259d7797db..a99a2b5903d7 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 f0932a0bd1de..13d740cdb0fb 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<g_flags_Group>,
> >    HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
> >    Values<"split,single">;
> >  def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">,
> > Group<g_flags_Group>;
> > +def gsimple_template_names : Flag<["-"], "gsimple-template-names">,
> > Group<g_flags_Group>;
> > +def gsimple_template_names_EQ
> > +    : Joined<["-"], "gsimple-template-names=">,
> > +      Group<g_flags_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<g_flags_Group>;
> >  def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>,
> > Flags<[CC1Option]>;
> >  def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">,
> > Group<g_flags_Group>;
> >  def gpubnames : Flag<["-"], "gpubnames">, Group<g_flags_Group>,
> > Flags<[CC1Option]>;
> >
> > diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp
> > b/clang/lib/Driver/ToolChains/Clang.cpp
> > index e6742c6575b9..6c7b8bbcaad7 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 10b2e96e8957..2368e6884188 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 4bf2c202dacf..5f652cb49b71 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='
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> > bin/mailman/listinfo/cfe-commits__;!!JmoZiZGBv3RvKRSx!sx4rLw3CFwdj-
> > rfDEK1Ah3HnANZSLOpXYFIcie1Oiyili8LKwFHxFk-g0F5_mAxhFw$


More information about the cfe-commits mailing list