From 79dc9d7304c9baa19a7156f7c6f40287fec20f46 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Wed, 6 Jan 2016 01:37:57 +0000 Subject: [PATCH] Avoid assert failure on some invalid cc1 options. Addressing review comment in D13221. Differential Revision: http://reviews.llvm.org/D15882 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256897 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInvocation.cpp | 27 +++++++++++++++++++-------- test/Driver/debug-options.c | 5 +++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index d3870424b6..621acca6f4 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -399,18 +399,29 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, } if (Arg *A = Args.getLastArg(OPT_debug_info_kind_EQ)) { - Opts.setDebugInfo( - llvm::StringSwitch(A->getValue()) + unsigned Val = + llvm::StringSwitch(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(Val)); } if (Arg *A = Args.getLastArg(OPT_debugger_tuning_EQ)) { - Opts.setDebuggerTuning( - llvm::StringSwitch(A->getValue()) - .Case("gdb", CodeGenOptions::DebuggerKindGDB) - .Case("lldb", CodeGenOptions::DebuggerKindLLDB) - .Case("sce", CodeGenOptions::DebuggerKindSCE)); + unsigned Val = llvm::StringSwitch(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(Val)); } Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 0, Diags); Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); diff --git a/test/Driver/debug-options.c b/test/Driver/debug-options.c index e160b7fd32..72d0136a8c 100644 --- a/test/Driver/debug-options.c +++ b/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' -- 2.40.0