]> granicus.if.org Git - clang/commitdiff
[driver] Don't blindly accept all -g options.
authorChad Rosier <mcrosier@apple.com>
Fri, 4 Nov 2011 19:28:44 +0000 (19:28 +0000)
committerChad Rosier <mcrosier@apple.com>
Fri, 4 Nov 2011 19:28:44 +0000 (19:28 +0000)
rdar://10383444

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/debug-options.c [new file with mode: 0644]

index 4f84d0a0dd218a04143ca8e21566a30166bb6a71..8c0382fbf3a207b273a4f5c0af6a5c02ef022dc8 100644 (file)
@@ -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<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);
diff --git a/test/Driver/debug-options.c b/test/Driver/debug-options.c
new file mode 100644 (file)
index 0000000..8672519
--- /dev/null
@@ -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"