mirror of https://github.com/microsoft/clang.git
[Driver] Don't crash on invalid values of -mrelocation-model=.
This is handled in a similar way we handle invalid -mcode-model. PR: 31840 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299315 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5285209f96
commit
d11ae8abf6
|
@ -323,7 +323,8 @@ static llvm::CodeModel::Model getCodeModel(const CodeGenOptions &CodeGenOpts) {
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -330,6 +330,17 @@ static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags) {
|
|||
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(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
|
|||
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)
|
||||
|
|
|
@ -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'
|
Loading…
Reference in New Issue