aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2025-07-02 09:39:46 +0900
committerGitHub <noreply@github.com>2025-07-02 09:39:46 +0900
commit7502af89fc0e025cb4d98f1a178a330fbf5e9d37 (patch)
tree24f4da654ddc5f86e2b9ad876d78798015be1525 /clang/lib/Frontend/CompilerInvocation.cpp
parentb0e6faae0842f5e7ad900dd448fb782737bb3612 (diff)
downloadllvm-7502af89fc0e025cb4d98f1a178a330fbf5e9d37.zip
llvm-7502af89fc0e025cb4d98f1a178a330fbf5e9d37.tar.gz
llvm-7502af89fc0e025cb4d98f1a178a330fbf5e9d37.tar.bz2
clang: Forward exception_model flag for bitcode inputs (#146342)
This will enable removal of a hack from the wasm backend in a future change. This feels unnecessarily clunky. I would assume something was automatically parsing this and propagating it in the C++ case, but I can't seem to find it. In particular it feels wrong that I need to parse out the individual values, given they are listed in the options.td file. We should also be parsing and forwarding every flag that corresponds to something else in TargetOptions, which requires auditing.
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f366e90..d8916a6 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3679,6 +3679,22 @@ static StringRef GetInputKindName(InputKind IK) {
llvm_unreachable("unknown input language");
}
+static StringRef getExceptionHandlingName(unsigned EHK) {
+ switch (static_cast<LangOptions::ExceptionHandlingKind>(EHK)) {
+ case LangOptions::ExceptionHandlingKind::None:
+ default:
+ return "none";
+ case LangOptions::ExceptionHandlingKind::SjLj:
+ return "sjlj";
+ case LangOptions::ExceptionHandlingKind::DwarfCFI:
+ return "dwarf";
+ case LangOptions::ExceptionHandlingKind::Wasm:
+ return "wasm";
+ }
+
+ llvm_unreachable("covered switch");
+}
+
void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
ArgumentConsumer Consumer,
const llvm::Triple &T,
@@ -3694,6 +3710,10 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
GenerateArg(Consumer, OPT_pic_is_pie);
for (StringRef Sanitizer : serializeSanitizerKinds(Opts.Sanitize))
GenerateArg(Consumer, OPT_fsanitize_EQ, Sanitizer);
+ if (Opts.ExceptionHandling) {
+ GenerateArg(Consumer, OPT_exception_model,
+ getExceptionHandlingName(Opts.ExceptionHandling));
+ }
return;
}
@@ -4002,6 +4022,24 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
Diags, Opts.Sanitize);
+ if (const Arg *A = Args.getLastArg(options::OPT_exception_model)) {
+ std::optional<LangOptions::ExceptionHandlingKind> EMValue =
+ llvm::StringSwitch<std::optional<LangOptions::ExceptionHandlingKind>>(
+ A->getValue())
+ .Case("dwarf", LangOptions::ExceptionHandlingKind::DwarfCFI)
+ .Case("sjlj", LangOptions::ExceptionHandlingKind::SjLj)
+ .Case("wineh", LangOptions::ExceptionHandlingKind::WinEH)
+ .Case("wasm", LangOptions::ExceptionHandlingKind::Wasm)
+ .Case("none", LangOptions::ExceptionHandlingKind::None)
+ .Default(std::nullopt);
+ if (EMValue) {
+ Opts.ExceptionHandling = static_cast<unsigned>(*EMValue);
+ } else {
+ Diags.Report(diag::err_drv_invalid_value)
+ << A->getAsString(Args) << A->getValue();
+ }
+ }
+
return Diags.getNumErrors() == NumErrorsBefore;
}