diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 85204ceaa49a..4336a25f091c 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -490,14 +490,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC, Default); } -static bool ShouldDisableDwarfDirectory(const ArgList &Args, - const ToolChain &TC) { - bool UseDwarfDirectory = - Args.hasFlag(options::OPT_fdwarf_directory_asm, - options::OPT_fno_dwarf_directory_asm, TC.useIntegratedAs()); - return !UseDwarfDirectory; -} - // Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases // to the corresponding DebugInfoKind. static codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg &A) { @@ -4175,6 +4167,14 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D, } } + // To avoid join/split of directory+filename, the integrated assembler prefers + // the directory form of .file on all DWARF versions. GNU as doesn't allow the + // form before DWARF v5. + if (!Args.hasFlag(options::OPT_fdwarf_directory_asm, + options::OPT_fno_dwarf_directory_asm, + TC.useIntegratedAs() || EffectiveDWARFVersion >= 5)) + CmdArgs.push_back("-fno-dwarf-directory-asm"); + // 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) @@ -5506,9 +5506,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fno-gnu-keywords"); } - if (ShouldDisableDwarfDirectory(Args, TC)) - CmdArgs.push_back("-fno-dwarf-directory-asm"); - if (!ShouldEnableAutolink(Args, TC, JA)) CmdArgs.push_back("-fno-autolink"); diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index 54a8a6a3f74a..3b1f1d555bbc 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -424,3 +424,14 @@ // 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' + +/// Default to -fno-dwarf-directory-asm for -fno-integrated-as before DWARF v5. +// RUN: %clang -### -target x86_64 -c -gdwarf-2 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s +// RUN: %clang -### -target x86_64 -c -gdwarf-5 %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s +// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s +// RUN: %clang -### -target x86_64 -c -gdwarf-5 -fno-integrated-as %s 2>&1 | FileCheck --check-prefix=DIRECTORY %s + +// RUN: %clang -### -target x86_64 -c -gdwarf-4 -fno-dwarf-directory-asm %s 2>&1 | FileCheck --check-prefix=NODIRECTORY %s + +// DIRECTORY-NOT: "-fno-dwarf-directory-asm" +// NODIRECTORY: "-fno-dwarf-directory-asm"