[PATCH] D145726: Fix assembler error when -g and -gdwarf-* is passed with -fno-integrated-as.
garvit gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 25 11:31:43 PDT 2023
garvitgupta08 updated this revision to Diff 508328.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145726/new/
https://reviews.llvm.org/D145726
Files:
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/as-options.cpp
clang/test/Driver/gcc_forward.c
Index: clang/test/Driver/gcc_forward.c
===================================================================
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -34,3 +34,15 @@
// CHECK-NOT: "-Wall"
// CHECK-NOT: "-Wdocumentation"
// CHECK: "-o" "a.out"
+//
+// Test that -g and -gdwarf-* are not passed through to GAS.
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -g -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g \
+// RUN: -fdebug-default-version=4 -c %s -### 2>&1 | FileCheck --check-prefix=DEBUG %s
+// DEBUG-NOT: "-g"
+// DEBUG-NOT: "-gdwarf-4"
\ No newline at end of file
Index: clang/test/Driver/as-options.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/as-options.cpp
@@ -0,0 +1,11 @@
+// Test that -g and -gdwarf-* are not passed through to GAS.
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -g -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g \
+// RUN: -fdebug-default-version=4 -c %s -### 2>&1 | FileCheck --check-prefix=DEBUG %s
+// DEBUG-NOT: "-g"
+// DEBUG-NOT: "-gdwarf-4"
\ No newline at end of file
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -972,19 +972,27 @@
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (const auto &II : Inputs)
- CmdArgs.push_back(II.getFilename());
-
- if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
- options::OPT_gdwarf_2, options::OPT_gdwarf_3,
- options::OPT_gdwarf_4, options::OPT_gdwarf_5,
- options::OPT_gdwarf))
- if (!A->getOption().matches(options::OPT_g0)) {
- Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
- unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
- CmdArgs.push_back(Args.MakeArgString("-gdwarf-" + Twine(DwarfVersion)));
- }
+ bool IsInputTyAsm = false;
+ for (const auto &II : Inputs) {
+ CmdArgs.push_back(II.getFilename());
+ StringRef BaseInput = StringRef(II.getBaseInput());
+ types::ID InputType = types::lookupTypeForExtension(
+ llvm::sys::path::extension(BaseInput).drop_front());
+ if (InputType == types::TY_Asm || InputType == types::TY_PP_Asm)
+ IsInputTyAsm = true;
+ }
+
+ if (IsInputTyAsm)
+ if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
+ options::OPT_gdwarf_2, options::OPT_gdwarf_3,
+ options::OPT_gdwarf_4, options::OPT_gdwarf_5,
+ options::OPT_gdwarf))
+ if (!A->getOption().matches(options::OPT_g0)) {
+ Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
+ unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
+ CmdArgs.push_back(Args.MakeArgString("-gdwarf-" + Twine(DwarfVersion)));
+ }
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145726.508328.patch
Type: text/x-patch
Size: 3862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230325/2d208c26/attachment.bin>
More information about the cfe-commits
mailing list