diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -976,6 +976,10 @@ for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); + if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group)) + if (!A->getOption().matches(options::OPT_g0)) + Args.AddLastArg(CmdArgs, options::OPT_g_Flag); + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler)); C.addCommand(std::make_unique(JA, *this, diff --git a/clang/test/Driver/as-options.s b/clang/test/Driver/as-options.s --- a/clang/test/Driver/as-options.s +++ b/clang/test/Driver/as-options.s @@ -116,3 +116,13 @@ // RUN: %clang -mrelax-all -fno-integrated-as -x c++ %s -S -o /dev/null 2>&1 \ // RUN: | FileCheck --check-prefix=WARN --allow-empty %s // WARN: unused + +// Test that -g is passed through to GAS. +// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=DEBUG %s +// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g0 -g %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=DEBUG %s +// DEBUG: "-g" +// RUN: %clang --target=aarch64-linux-gnu -fno-integrated-as -g -g0 %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=NODEBUG %s +// NODEBUG-NOT: "-g"