Author: Igor Kudrin Date: 2021-02-18T10:36:42+07:00 New Revision: a0c9ec1f5e70e8f15da170667b2a8e63d024f3ab
URL: https://github.com/llvm/llvm-project/commit/a0c9ec1f5e70e8f15da170667b2a8e63d024f3ab DIFF: https://github.com/llvm/llvm-project/commit/a0c9ec1f5e70e8f15da170667b2a8e63d024f3ab.diff LOG: [Driver] Honor "-gdwarf-N" at any position for assembler sources This fixes an issue when "-gdwarf-N" switch was ignored if it was given before another debug option. Differential Revision: https://reviews.llvm.org/D96865 Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/debug-options-as.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 2ae6c400f692..eaaef6b78ffb 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -981,6 +981,14 @@ static unsigned DwarfVersionNum(StringRef ArgValue) { .Default(0); } +// Find a DWARF format version option. +// This function is a complementary for DwarfVersionNum(). +static const Arg *getDwarfNArg(const ArgList &Args) { + return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3, + options::OPT_gdwarf_4, options::OPT_gdwarf_5, + options::OPT_gdwarf); +} + static void RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs, codegenoptions::DebugInfoKind DebugInfoKind, unsigned DwarfVersion, @@ -3848,9 +3856,7 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, } // If a -gdwarf argument appeared, remember it. - const Arg *GDwarfN = Args.getLastArg( - options::OPT_gdwarf_2, options::OPT_gdwarf_3, options::OPT_gdwarf_4, - options::OPT_gdwarf_5, options::OPT_gdwarf); + const Arg *GDwarfN = getDwarfNArg(Args); bool EmitDwarf = false; if (GDwarfN) { if (checkDebugInfoOption(GDwarfN, Args, D, TC)) @@ -7168,18 +7174,14 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, // Forward -g and handle debug info related flags, assuming we are dealing // with an actual assembly file. bool WantDebug = false; - unsigned DwarfVersion = 0; Args.ClaimAllArgs(options::OPT_g_Group); - if (Arg *A = Args.getLastArg(options::OPT_g_Group)) { + if (Arg *A = Args.getLastArg(options::OPT_g_Group)) WantDebug = !A->getOption().matches(options::OPT_g0) && !A->getOption().matches(options::OPT_ggdb0); - if (WantDebug) - DwarfVersion = DwarfVersionNum(A->getSpelling()); - } - unsigned DefaultDwarfVersion = ParseDebugDefaultVersion(getToolChain(), Args); - if (DwarfVersion == 0) - DwarfVersion = DefaultDwarfVersion; + unsigned DwarfVersion = ParseDebugDefaultVersion(getToolChain(), Args); + if (const Arg *GDwarfN = getDwarfNArg(Args)) + DwarfVersion = DwarfVersionNum(GDwarfN->getSpelling()); if (DwarfVersion == 0) DwarfVersion = getToolChain().GetDefaultDwarfVersion(); diff --git a/clang/test/Driver/debug-options-as.c b/clang/test/Driver/debug-options-as.c index f36188e8ab2b..000090062d7d 100644 --- a/clang/test/Driver/debug-options-as.c +++ b/clang/test/Driver/debug-options-as.c @@ -60,3 +60,18 @@ // GDWARF64_VER: error: invalid argument '-gdwarf64' only allowed with 'DWARFv3 or greater' // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 bit architecture' // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF platforms' + +// Check that -gdwarf-N can be placed before other options of the "-g" group. +// RUN: %clang -### -c -g -gdwarf-3 -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DWARF3 %s +// RUN: %clang -### -c -gdwarf-3 -g -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DWARF3 %s +// RUN: %clang -### -c -g -gdwarf-5 -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DWARF5 %s +// RUN: %clang -### -c -gdwarf-5 -g -target %itanium_abi_triple -fintegrated-as -x assembler %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DWARF5 %s + +// DWARF3: "-cc1as" +// DWARF3: "-dwarf-version=3" +// DWARF5: "-cc1as" +// DWARF5: "-dwarf-version=5" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits