[PATCH] D15882: Avoid assert failure on some invalid cc1 options.

Douglas Katzman via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 4 19:51:46 PST 2016


dougk created this revision.
dougk added reviewers: thakis, probinson.
dougk added a subscriber: cfe-commits.

Something like this was suggested in http://reviews.llvm.org/D13221


http://reviews.llvm.org/D15882

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===================================================================
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -169,3 +169,8 @@
 // NOCI-NOT: "-dwarf-column-info"
 //
 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj" "-debug-info-kind={{standalone|limited}}"
+
+// RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
+// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
+// RUN: not %clang -cc1 -debugger-tuning=gmodal 2>&1 | FileCheck -check-prefix=BADSTRING2 %s
+// BADSTRING2: error: invalid value 'gmodal' in '-debugger-tuning=gmodal'
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -399,18 +399,29 @@
   }
 
   if (Arg *A = Args.getLastArg(OPT_debug_info_kind_EQ)) {
-    Opts.setDebugInfo(
-        llvm::StringSwitch<CodeGenOptions::DebugInfoKind>(A->getValue())
+    unsigned Val =
+        llvm::StringSwitch<unsigned>(A->getValue())
             .Case("line-tables-only", CodeGenOptions::DebugLineTablesOnly)
             .Case("limited", CodeGenOptions::LimitedDebugInfo)
-            .Case("standalone", CodeGenOptions::FullDebugInfo));
+            .Case("standalone", CodeGenOptions::FullDebugInfo)
+            .Default(~0U);
+    if (Val == ~0U)
+      Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
+                                                << A->getValue();
+    else
+      Opts.setDebugInfo(static_cast<CodeGenOptions::DebugInfoKind>(Val));
   }
   if (Arg *A = Args.getLastArg(OPT_debugger_tuning_EQ)) {
-    Opts.setDebuggerTuning(
-        llvm::StringSwitch<CodeGenOptions::DebuggerKind>(A->getValue())
-            .Case("gdb", CodeGenOptions::DebuggerKindGDB)
-            .Case("lldb", CodeGenOptions::DebuggerKindLLDB)
-            .Case("sce", CodeGenOptions::DebuggerKindSCE));
+    unsigned Val = llvm::StringSwitch<unsigned>(A->getValue())
+                       .Case("gdb", CodeGenOptions::DebuggerKindGDB)
+                       .Case("lldb", CodeGenOptions::DebuggerKindLLDB)
+                       .Case("sce", CodeGenOptions::DebuggerKindSCE)
+                       .Default(~0U);
+    if (Val == ~0U)
+      Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
+                                                << A->getValue();
+    else
+      Opts.setDebuggerTuning(static_cast<CodeGenOptions::DebuggerKind>(Val));
   }
   Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 0, Diags);
   Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15882.43958.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160105/149e1cc8/attachment.bin>


More information about the cfe-commits mailing list