diff options
author | Davide Italiano <davide@freebsd.org> | 2017-04-01 21:07:07 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-04-01 21:07:07 +0000 |
commit | d11ae8abf6a042aa838045a82696022fdfe353e5 (patch) | |
tree | 4cbcdc317407955541e6a0bd289eb6aeaf942e69 /lib/Frontend/CompilerInvocation.cpp | |
parent | 5285209f96486181a4179963f5f3c6ba2a375607 (diff) | |
download | clang-d11ae8abf6a042aa838045a82696022fdfe353e5.tar.gz |
[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
Diffstat (limited to 'lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index a9d805b7db..9138450181 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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) |