garvitgupta08 updated this revision to Diff 507144. garvitgupta08 marked an inline comment as not done.
Repository: rG LLVM Github Monorepo 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));
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));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits