[llvm-branch-commits] [clang] [llvm] CodeGen: Remove TargetOptions::ExceptionModel (PR #232977)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 16 16:06:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
The exception model now comes only from the "exception-model" module
flag. Remove the TargetOptions field and its copy into MCAsmInfo, so
MCAsmInfo only knows the target's default model.
The WebAssembly model checks move from the TargetMachine constructor
into the Emscripten EH/SjLj lowering pass. Clang relied on the backend
to reject non-wasm models for wasm targets, so it now rejects them
itself.
Co-authored-by: Claude Opus 5.5 <noreply@<!-- -->anthropic.com>
---
Patch is 27.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/232977.diff
26 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (-11)
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+6)
- (modified) clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll (+4-3)
- (modified) llvm/include/llvm/MC/MCAsmInfo.h (+13-17)
- (modified) llvm/include/llvm/Target/TargetOptions.h (-3)
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+4-5)
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp (+4-3)
- (modified) llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp (+1-1)
- (modified) llvm/lib/CodeGen/CFIInstrInserter.cpp (+4)
- (modified) llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp (-3)
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (-1)
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+3-4)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-1)
- (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+1-1)
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+1-1)
- (modified) llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (+2-2)
- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+2-2)
- (modified) llvm/lib/Target/ARM/ARMTargetObjectFile.cpp (+2-1)
- (modified) llvm/lib/Target/ARM/ARMTargetObjectFile.h (+2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp (+9-2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp (+2-31)
- (modified) llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp (+3-5)
- (modified) llvm/lib/Target/X86/X86MCInstLower.cpp (+1-1)
- (modified) llvm/lib/Target/X86/X86TargetMachine.cpp (+3-5)
- (modified) llvm/test/CodeGen/AMDGPU/exception-model.ll (+22-4)
- (modified) llvm/test/CodeGen/X86/llc-pipeline-npm.ll (+2)
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 77c53c612df8f..7b993f08280c2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -392,17 +392,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.UseInitArray = CodeGenOpts.UseInitArray;
Options.MCOptions.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
- if (CodeGenOpts.hasSjLjExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
- if (CodeGenOpts.hasSEHExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
- if (CodeGenOpts.hasDWARFExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
- if (CodeGenOpts.hasWasmExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
- if (CodeGenOpts.hasEmscriptenExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::Emscripten;
-
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.BBAddrMap = CodeGenOpts.BBAddrMap;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index c9281c2a6d6b4..91378a8436a95 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -577,6 +577,12 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
Diags.Report(diag::err_fe_invalid_exception_model)
<< static_cast<unsigned>(CodeGenOpts.getExceptionHandling()) << T.str();
+ if (T.isWasm() &&
+ (CodeGenOpts.hasSjLjExceptions() || CodeGenOpts.hasSEHExceptions() ||
+ CodeGenOpts.hasDWARFExceptions()))
+ Diags.Report(diag::err_fe_invalid_exception_model)
+ << static_cast<unsigned>(CodeGenOpts.getExceptionHandling()) << T.str();
+
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
Diags.Report(diag::warn_c_kext);
diff --git a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
index b3ac28b472267..ada198e466f4f 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
+++ b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
@@ -5,8 +5,8 @@
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=wasm %s | FileCheck -check-prefixes=CHECK,WASM %s
; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=invalid %s 2>&1 | FileCheck -check-prefix=ERR %s
-; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
-; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
+; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s 2>&1 | FileCheck -check-prefix=ERR-DWARF %s
+; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s 2>&1 | FileCheck -check-prefix=ERR-SJLJ %s
; CHECK-LABEL: define void @test(
@@ -15,7 +15,8 @@
; WASM: !{i32 1, !"exception-model", !"wasm"}
; ERR: error: invalid value 'invalid' in '-exception-model=invalid'
-; ERR-BE: fatal error: error in backend: -exception-model should be either 'none', 'wasm', or 'emscripten'
+; ERR-DWARF: error: invalid exception model 'dwarf' for target 'wasm32'
+; ERR-SJLJ: error: invalid exception model 'sjlj' for target 'wasm32'
define void @test() {
ret void
}
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 3a9f3c3264bc8..6e7b6f1b06c58 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -353,11 +353,12 @@ class LLVM_ABI MCAsmInfo {
/// false.
bool SupportsDebugInformation = false;
- /// Exception handling format for the target. Defaults to None.
+ /// Default exception handling model for the target. Defaults to None.
ExceptionHandling ExceptionsType = ExceptionHandling::None;
/// True if target uses CFI unwind information for other purposes than EH
- /// (debugging / sanitizers) when `ExceptionsType == ExceptionHandling::None`.
+ /// (debugging / sanitizers) when the exception model is
+ /// `ExceptionHandling::None`.
bool UsesCFIWithoutEH = false;
/// Windows exception handling data (.pdata) encoding. Defaults to Invalid.
@@ -656,21 +657,16 @@ class LLVM_ABI MCAsmInfo {
ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
- void setExceptionsType(ExceptionHandling EH) {
- ExceptionsType = EH;
+ bool usesCFIWithoutEH(ExceptionHandling EH) const {
+ return EH == ExceptionHandling::None && UsesCFIWithoutEH;
}
- bool usesCFIWithoutEH() const {
- return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH;
- }
-
- /// Returns true if the exception handling method for the platform uses call
- /// frame information to unwind.
- bool usesCFIForEH() const {
- return (ExceptionsType == ExceptionHandling::DwarfCFI ||
- ExceptionsType == ExceptionHandling::ARM ||
- ExceptionsType == ExceptionHandling::ZOS ||
- (ExceptionsType == ExceptionHandling::WinEH && usesWindowsCFI()));
+ /// Returns true if the exception handling method \p EH uses call frame
+ /// information to unwind.
+ bool usesCFIForEH(ExceptionHandling EH) const {
+ return EH == ExceptionHandling::DwarfCFI || EH == ExceptionHandling::ARM ||
+ EH == ExceptionHandling::ZOS ||
+ (EH == ExceptionHandling::WinEH && usesWindowsCFI());
}
/// Returns true if the object format describes unwind information with
@@ -684,8 +680,8 @@ class LLVM_ABI MCAsmInfo {
/// Returns true if the exception tables reference the per-invoke EH labels
/// emitted around invokes. 32-bit x86 SEH and Wasm do not.
- bool usesPerInvokeEHLabels() const {
- switch (ExceptionsType) {
+ bool usesPerInvokeEHLabels(ExceptionHandling EH) const {
+ switch (EH) {
case ExceptionHandling::WinEH:
// 32-bit x86 SEH uses a state table, not per-invoke IP-to-state ranges.
return WinEHEncodingType != WinEH::EncodingType::X86;
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index 264db07ded991..31decfe069eac 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -311,9 +311,6 @@ class TargetOptions {
VectorLibrary VecLib = VectorLibrary::NoLibrary;
public:
- /// What exception model to use
- ExceptionHandling ExceptionModel = ExceptionHandling::Default;
-
/// Machine level options.
MCTargetOptions MCOptions;
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index bb1c27d86c2e8..35e9d3388a487 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1419,13 +1419,11 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
if (F.isDeclarationForLinker())
return CFISection::None;
- // A DwarfCFI module only carries EH unwind info if the target actually uses
- // CFI for exceptions.
if (ModuleExceptionModel == ExceptionHandling::DwarfCFI &&
- MAI.usesCFIForEH() && F.needsUnwindTableEntry())
+ F.needsUnwindTableEntry())
return CFISection::EH;
- if (MAI.usesCFIWithoutEH() && F.hasUWTable())
+ if (MAI.usesCFIWithoutEH(ModuleExceptionModel) && F.hasUWTable())
return CFISection::EH;
if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
@@ -1440,7 +1438,8 @@ AsmPrinter::getFunctionCFISectionType(const MachineFunction &MF) const {
}
bool AsmPrinter::usesCFIWithoutEH() const {
- return MAI.usesCFIWithoutEH() && ModuleCFISection != CFISection::None;
+ return MAI.usesCFIWithoutEH(ModuleExceptionModel) &&
+ ModuleCFISection != CFISection::None;
}
void AsmPrinter::emitCFIInstruction(const MachineInstr &MI) {
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
index 3b2feb876eadb..cfd539265012c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
@@ -37,7 +37,7 @@ void DwarfCFIException::addPersonality(const GlobalValue *Personality) {
/// content.
void DwarfCFIException::endModule() {
// SjLj uses this pass and it doesn't need this info.
- if (!Asm->MAI.usesCFIForEH())
+ if (!Asm->MAI.usesCFIForEH(Asm->getModuleExceptionModel()))
return;
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
@@ -92,9 +92,10 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) {
LSDAEncoding != dwarf::DW_EH_PE_omit;
const MCAsmInfo &MAI = MF->getContext().getAsmInfo();
- if (Asm->getModuleExceptionModel() != ExceptionHandling::None)
+ ExceptionHandling EH = Asm->getModuleExceptionModel();
+ if (EH != ExceptionHandling::None)
shouldEmitCFI =
- MAI.usesCFIForEH() && (shouldEmitPersonality || shouldEmitMoves);
+ (shouldEmitPersonality || shouldEmitMoves) && MAI.usesCFIForEH(EH);
else
shouldEmitCFI = Asm->usesCFIWithoutEH() && shouldEmitMoves;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index 3fd4494a53ffc..fb4b21b5d8c6a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -297,7 +297,7 @@ void EHStreamer::computeCallSiteTable(
// throw, create a call-site entry with no landing pad for the region
// between the try-ranges.
if (SawPotentiallyThrowing &&
- (Asm->MAI.usesCFIForEH() ||
+ (Asm->MAI.usesCFIForEH(Asm->getModuleExceptionModel()) ||
Asm->getModuleExceptionModel() == ExceptionHandling::AIX)) {
CallSites.push_back({LastLabel, BeginLabel, nullptr, 0});
PreviousIsInvoke = false;
diff --git a/llvm/lib/CodeGen/CFIInstrInserter.cpp b/llvm/lib/CodeGen/CFIInstrInserter.cpp
index a415dee9f3938..da3501330f7b8 100644
--- a/llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ b/llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -42,6 +42,10 @@ class CFIInstrInserterImpl {
if (!MF.needsFrameMoves())
return false;
+ // Functions with Windows unwind info have no DWARF CFI to fix up.
+ if (MF.usesWindowsUnwindInfo())
+ return false;
+
MBBVector.resize(MF.getNumBlockIDs());
calculateCFAInfo(MF);
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index d32895d47369d..f61ab04b04e21 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -84,9 +84,6 @@ void CodeGenTargetMachineImpl::initAsmInfo() {
getTargetTriple().getDefaultExceptionHandling() &&
"MCAsmInfo and Triple disagree on default exception handling type");
- if (Options.ExceptionModel != ExceptionHandling::Default)
- TmpAsmInfo->setExceptionsType(Options.ExceptionModel);
-
AsmInfo.reset(TmpAsmInfo);
}
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 3c4652405cb6a..a780abce7e5bb 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -539,7 +539,6 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
getExplicitEmulatedTLS().value_or(TheTriple.hasDefaultEmulatedTLS());
Options.EnableTLSDESC =
getExplicitEnableTLSDESC().value_or(TheTriple.hasDefaultTLSDESC());
- Options.ExceptionModel = getExceptionModel();
Options.VecLib = getVectorLibrary();
Options.EmitStackSizeSection = getEnableStackSizeSection();
Options.EnableStaticDataPartitioning = getEnableStaticDataPartitioning();
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index b0f06907ef9da..8eca698cc7bee 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -749,13 +749,12 @@ bool MachineFunction::needsFrameMoves() const {
}
bool MachineFunction::usesWindowsUnwindInfo() const {
- const MCAsmInfo &MAI = getTarget().getMCAsmInfo();
- return MAI.getExceptionHandlingType() == ExceptionHandling::WinEH &&
- MAI.usesWindowsCFI();
+ return getTarget().getMCAsmInfo().usesWindowsCFI() &&
+ F.getParent()->getExceptionModel() == ExceptionHandling::WinEH;
}
bool MachineFunction::needsWinCFI() const {
- return usesWindowsUnwindInfo() && getFunction().needsUnwindTableEntry();
+ return getFunction().needsUnwindTableEntry() && usesWindowsUnwindInfo();
}
bool MachineFunction::disableFramePointerElim() const {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 7ed3ed4ae9b8e..2ef082a432ce5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9291,7 +9291,8 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
// Skip emitting EH_LABEL on targets whose exception tables don't reference
// them (32-bit x86 SEH, Wasm).
- if (!MF.getContext().getAsmInfo().usesPerInvokeEHLabels()) {
+ if (!MF.getContext().getAsmInfo().usesPerInvokeEHLabels(
+ FuncInfo.ExceptionModel)) {
BeginLabel = nullptr;
return Chain;
}
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 8064f993e0a4e..c7f8a2e1b8915 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -717,7 +717,7 @@ RTLIB::Libcall RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
const TargetSubtargetInfo &STI)
: TM(tm),
- RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
+ RuntimeLibcallInfo(TM.getTargetTriple(), ExceptionHandling::Default,
TM.getTargetTriple().getDefaultFloatABI(),
TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
Libcalls(RuntimeLibcallInfo, [&STI](LibcallLoweringInfo &Info) {
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index acff5e19b06d7..fa46420336bcc 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -133,7 +133,7 @@ void TargetLoweringObjectFileELF::initialize(MCContext &Ctx,
case Triple::armeb:
case Triple::thumb:
case Triple::thumbeb:
- if (Ctx.getAsmInfo().getExceptionHandlingType() == ExceptionHandling::ARM)
+ if (M.getExceptionModel() == ExceptionHandling::ARM)
break;
// Fallthrough if not using EHABI
[[fallthrough]];
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 683b8ffb94e43..eb7b3228df9b1 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -3589,7 +3589,7 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
return;
case AArch64::EMITBKEY: {
- ExceptionHandling ExceptionHandlingType = MAI.getExceptionHandlingType();
+ ExceptionHandling ExceptionHandlingType = getModuleExceptionModel();
if (ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
ExceptionHandlingType != ExceptionHandling::ARM)
return;
@@ -3602,7 +3602,7 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
}
case AArch64::EMITMTETAGGED: {
- ExceptionHandling ExceptionHandlingType = MAI.getExceptionHandlingType();
+ ExceptionHandling ExceptionHandlingType = getModuleExceptionModel();
if (ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
ExceptionHandlingType != ExceptionHandling::ARM)
return;
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 9bbd029495a79..d118a21d56001 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -1411,7 +1411,7 @@ void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
PadBefore = -MI->getOperand(4).getImm() - 8;
break;
}
- if (MAI.getExceptionHandlingType() == ExceptionHandling::ARM) {
+ if (getModuleExceptionModel() == ExceptionHandling::ARM) {
if (PadBefore)
ATS.emitPad(PadBefore);
ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
@@ -1462,7 +1462,7 @@ void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
break;
}
- if (MAI.getExceptionHandlingType() == ExceptionHandling::ARM) {
+ if (getModuleExceptionModel() == ExceptionHandling::ARM) {
if (DstReg == FramePtr && FramePtr != ARM::SP)
// Set-up of the frame pointer. Positive values correspond to "add"
// instruction.
diff --git a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
index 6e0606f9d9d5c..2b92c9e29a463 100644
--- a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
@@ -41,6 +41,7 @@ void ARMElfTargetObjectFile::initialize(MCContext &Ctx, const TargetMachine &TM,
ARM_TM.getMCSubtargetInfo().hasFeature(ARM::FeatureExecuteOnly);
TargetLoweringObjectFileELF::initialize(Ctx, TM, M);
+ UsesARMEH = M.getExceptionModel() == ExceptionHandling::ARM;
// Make code section unreadable when in execute-only mode
if (genExecuteOnly) {
@@ -81,7 +82,7 @@ getIndirectSymViaRWPI(const MCSymbol *Sym) const {
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
- if (TM.getMCAsmInfo().getExceptionHandlingType() != ExceptionHandling::ARM)
+ if (!UsesARMEH)
return TargetLoweringObjectFileELF::getTTypeGlobalReference(
GV, Encoding, TM, MMI, Streamer);
diff --git a/llvm/lib/Target/ARM/ARMTargetObjectFile.h b/llvm/lib/Target/ARM/ARMTargetObjectFile.h
index 221a4be6579c6..b4b6777480fd2 100644
--- a/llvm/lib/Target/ARM/ARMTargetObjectFile.h
+++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.h
@@ -16,6 +16,8 @@
namespace llvm {
class ARMElfTargetObjectFile : public TargetLoweringObjectFileELF {
+ bool UsesARMEH = false;
+
public:
ARMElfTargetObjectFile();
void initialize(MCContext &Ctx, const TargetMachine &TM,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 81f9e5603e57b..e8ac89570741f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -918,9 +918,16 @@ bool WebAssemblyLowerEmscriptenEHSjLjImpl::runOnModule(Module &M) {
LLVM_DEBUG(dbgs() << "********** Lower Emscripten EH & SjLj **********\n");
ExceptionHandling EH = M.getExceptionModel();
+ if (EH != ExceptionHandling::None && EH != ExceptionHandling::Wasm &&
+ EH != ExceptionHandling::Emscripten)
+ report_fatal_error(
+ "-exception-model should be either 'none', 'wasm', or 'emscripten'");
+
EnableEmEH = EH == ExceptionHandling::Emscripten;
- assert((!EnableEmEH || !EnableWasmSjLj) &&
- "Wasm SjLj should be only used with Wasm EH");
+ // You can't mix Emscripten EH with Wasm SjLj.
+ if (EnableEmEH && EnableWasmSjLj)
+ report_fatal_error(
+ "-exception-model=emscripten not allowed with -wasm-enable-sjlj");
bool Changed = false;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index cd3ae6215746a..742c2541a2d58 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -128,40 +128,11 @@ using WebAssembly::WasmDisableExplicitLocals;
using WebAssembly::WasmEnableEmSjLj;
using WebAssembly::WasmEnableSjLj;
-static void basicCheckForEHAndSjLj(TargetMachine *TM) {
-
- bool EnableEmEH = TM->Options.ExceptionModel == ExceptionHandling::Emscripten;
-
+static void basicCheckForEHAndSjLj() {
// You can't enable two modes of SjLj at the same time
if (WasmE...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/232977
More information about the llvm-branch-commits
mailing list