[cfe-commits] r143732 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/debug-options.c
Chad Rosier
mcrosier at apple.com
Fri Nov 4 12:28:44 PDT 2011
Author: mcrosier
Date: Fri Nov 4 14:28:44 2011
New Revision: 143732
URL: http://llvm.org/viewvc/llvm-project?rev=143732&view=rev
Log:
[driver] Don't blindly accept all -g options.
rdar://10383444
Added:
cfe/trunk/test/Driver/debug-options.c
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=143732&r1=143731&r2=143732&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Nov 4 14:28:44 2011
@@ -1455,8 +1455,24 @@
// 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<bool>(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);
Added: cfe/trunk/test/Driver/debug-options.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-options.c?rev=143732&view=auto
==============================================================================
--- cfe/trunk/test/Driver/debug-options.c (added)
+++ cfe/trunk/test/Driver/debug-options.c Fri Nov 4 14:28:44 2011
@@ -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"
More information about the cfe-commits
mailing list