Author: davide Date: Sat Apr 1 16:07:07 2017 New Revision: 299315 URL: http://llvm.org/viewvc/llvm-project?rev=299315&view=rev Log: [Driver] Don't crash on invalid values of -mrelocation-model=.
This is handled in a similar way we handle invalid -mcode-model. PR: 31840 Added: cfe/trunk/test/Driver/reloc-model.c Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=299315&r1=299314&r2=299315&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sat Apr 1 16:07:07 2017 @@ -323,7 +323,8 @@ static llvm::CodeModel::Model getCodeMod } static llvm::Reloc::Model getRelocModel(const CodeGenOptions &CodeGenOpts) { - // Keep this synced with the equivalent code in tools/driver/cc1as_main.cpp. + // Keep this synced with the equivalent code in + // lib/Frontend/CompilerInvocation.cpp llvm::Optional<llvm::Reloc::Model> RM; RM = llvm::StringSwitch<llvm::Reloc::Model>(CodeGenOpts.RelocationModel) .Case("static", llvm::Reloc::Static) Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=299315&r1=299314&r2=299315&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Apr 1 16:07:07 2017 @@ -330,6 +330,17 @@ static StringRef getCodeModel(ArgList &A return "default"; } +static StringRef getRelocModel(ArgList &Args, DiagnosticsEngine &Diags) { + if (Arg *A = Args.getLastArg(OPT_mrelocation_model)) { + StringRef Value = A->getValue(); + if (Value == "static" || Value == "pic" || Value == "ropi" || + Value == "rwpi" || Value == "ropi-rwpi" || Value == "dynamic-no-pic") + return Value; + Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value; + } + return "pic"; +} + /// \brief Create a new Regex instance out of the string value in \p RpassArg. /// It returns a pointer to the newly generated Regex instance. static std::shared_ptr<llvm::Regex> @@ -615,7 +626,7 @@ static bool ParseCodeGenArgs(CodeGenOpti Args.hasArg(OPT_cl_unsafe_math_optimizations) || Args.hasArg(OPT_cl_fast_relaxed_math); Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); - Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); + Opts.RelocationModel = getRelocModel(Args, Diags); Opts.ThreadModel = Args.getLastArgValue(OPT_mthread_model, "posix"); if (Opts.ThreadModel != "posix" && Opts.ThreadModel != "single") Diags.Report(diag::err_drv_invalid_value) Added: cfe/trunk/test/Driver/reloc-model.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/reloc-model.c?rev=299315&view=auto ============================================================================== --- cfe/trunk/test/Driver/reloc-model.c (added) +++ cfe/trunk/test/Driver/reloc-model.c Sat Apr 1 16:07:07 2017 @@ -0,0 +1,4 @@ +// RUN: not %clang -cc1 -mrelocation-model tinkywinky \ +// RUN: -emit-llvm %s 2>&1 | FileCheck -check-prefix CHECK-INVALID %s + +// CHECK-INVALID: error: invalid value 'tinkywinky' in '-mrelocation-model tinkywinky' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits