From: Chad Rosier Date: Fri, 4 Nov 2011 19:28:44 +0000 (+0000) Subject: [driver] Don't blindly accept all -g options. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2875bda1505bce995f745002affb20862765ed04;p=clang [driver] Don't blindly accept all -g options. rdar://10383444 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143732 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4f84d0a0dd..8c0382fbf3 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1455,8 +1455,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // wrong. Args.ClaimAllArgs(options::OPT_g_Group); if (Arg *A = Args.getLastArg(options::OPT_g_Group)) - if (!A->getOption().matches(options::OPT_g0)) - CmdArgs.push_back("-g"); + if (!A->getOption().matches(options::OPT_g0)) { + StringRef ArgString = A->getAsString(Args); + bool Valid_g = llvm::StringSwitch(ArgString) + .Case("-g", true) + .Case("-g3", true) + .Case("-gdwarf-2", true) + .Case("-gstabs", true) + .Case("-gstabs+", true) + .Case("-gstabs1", true) + .Case("-gstabs2", true) + .Case("-gfull", true) + .Case("-gused", true) + .Default(false); + if (Valid_g) + CmdArgs.push_back("-g"); + else + D.Diag(diag::warn_drv_clang_unsupported) << ArgString; + } Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections); Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections); diff --git a/test/Driver/debug-options.c b/test/Driver/debug-options.c new file mode 100644 index 0000000000..867251971d --- /dev/null +++ b/test/Driver/debug-options.c @@ -0,0 +1,19 @@ +// Check to make sure clang is somewhat picky about -g options. +// rdar://10383444 + +// RUN: %clang -### -c -g %s 2>&1 | FileCheck -check-prefix=G %s +// RUN: %clang -### -c -g3 %s 2>&1 | FileCheck -check-prefix=G3 %s +// RUN: %clang -### -c -ganything %s 2>&1 | FileCheck -check-prefix=GANY %s +// RUN: %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=GFOO %s +// +// G: "-cc1" +// G: "-g" +// +// G3: "-cc1" +// G3: "-g" +// +// GANY: "-cc1" +// GANY-NOT: "-g" +// +// GFOO: "-cc1" +// GFOO-NOT: "-g"