[llvm] [WebAssembly] Fix exception handling initialization order in TargetMachine constructor (PR #177542)
Anutosh Bhat via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 23 21:44:03 PST 2026
https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/177542
>From ca5359fbd9e7f8097164453abff29003d3e17fb1 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Fri, 23 Jan 2026 13:36:29 +0530
Subject: [PATCH] [WebAssembly] Fix exception handling initialization order in
TargetMachine constructor
The WebAssemblyTargetMachine constructor had an ordering issue where
initAsmInfo() was called before basicCheckForEHAndSjLj(). This caused
problems in incremental compilation scenarios where:
1. initAsmInfo() sets MCAsmInfo exception type based on Options.ExceptionModel
2. But Options.ExceptionModel might still be None at this point
3. basicCheckForEHAndSjLj() runs later and updates Options.ExceptionModel
based on command-line flags like -wasm-enable-eh
4. MCAsmInfo retains the incorrect exception type (None instead of Wasm)
5. This prevents WebAssembly exception handling passes from running
The fix swaps the order so basicCheckForEHAndSjLj() runs first to
establish the correct exception model before initAsmInfo() configures
MCAsmInfo based on that model.
This enables WebAssembly exception handling to work correctly in
clang-repl and other incremental compilation scenarios.
---
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 402929caa760c..a57ebfad03b1c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -212,8 +212,8 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
this->Options.DataSections = true;
this->Options.UniqueSectionNames = true;
- initAsmInfo();
basicCheckForEHAndSjLj(this);
+ initAsmInfo();
// Note that we don't use setRequiresStructuredCFG(true). It disables
// optimizations than we're ok with, and want, such as critical edge
// splitting and tail merging.
More information about the llvm-commits
mailing list