diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 853a8cc20b46..91f7306bcdca 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -6227,24 +6227,28 @@ 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)) { + WantDebug = !A->getOption().matches(options::OPT_g0) && + !A->getOption().matches(options::OPT_ggdb0); + if (WantDebug) + DwarfVersion = DwarfVersionNum(A->getSpelling()); + } + if (DwarfVersion == 0) + DwarfVersion = getToolChain().GetDefaultDwarfVersion(); + + codegenoptions::DebugInfoKind DebugInfoKind = codegenoptions::NoDebugInfo; + if (SourceAction->getType() == types::TY_Asm || SourceAction->getType() == types::TY_PP_Asm) { - bool WantDebug = false; - unsigned DwarfVersion = 0; - Args.ClaimAllArgs(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()); - } - if (DwarfVersion == 0) - DwarfVersion = getToolChain().GetDefaultDwarfVersion(); - RenderDebugEnablingArgs(Args, CmdArgs, - (WantDebug ? codegenoptions::LimitedDebugInfo - : codegenoptions::NoDebugInfo), - DwarfVersion, llvm::DebuggerKind::Default); - + // You might think that it would be ok to set DebugInfoKind outside of + // the guard for source type, however there is a test which asserts + // that some assembler invocation receives no -debug-info-kind, + // and it's not clear whether that test is just overly restrictive. + DebugInfoKind = (WantDebug ? codegenoptions::LimitedDebugInfo + : codegenoptions::NoDebugInfo); // Add the -fdebug-compilation-dir flag if needed. addDebugCompDirArg(Args, CmdArgs); @@ -6257,6 +6261,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, // And pass along -I options Args.AddAllArgs(CmdArgs, options::OPT_I); } + RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DwarfVersion, + llvm::DebuggerKind::Default); // Handle -fPIC et al -- the relocation-model affects the assembler // for some targets. @@ -6314,12 +6320,6 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, // FIXME: Stop lying and consume only the appropriate driver flags Args.ClaimAllArgs(options::OPT_W_Group); - // Assemblers that want to know the dwarf version can't assume a value, - // since the defaulting logic resides in the driver. Put in something - // reasonable now, in case a subsequent "-Wa,-g" changes it. - RenderDebugEnablingArgs(Args, CmdArgs, codegenoptions::NoDebugInfo, - getToolChain().GetDefaultDwarfVersion(), - llvm::DebuggerKind::Default); CollectArgsForIntegratedAssembler(C, Args, CmdArgs, getToolChain().getDriver());