Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WebAssembly] Fix crash combining complex numbers and multivalue#200514

Merged
dschuff merged 1 commit into
llvm:mainfrom
alexcrichton:compelx-fix
Jun 4, 2026
Merged

[WebAssembly] Fix crash combining complex numbers and multivalue#200514
dschuff merged 1 commit into
llvm:mainfrom
alexcrichton:compelx-fix

Conversation

@alexcrichton
Copy link
Copy Markdown
Contributor

@alexcrichton alexcrichton commented May 29, 2026

This fixes a crash in Clang when the experimental-mv ABI is used on WebAssembly targets in conjunction with complex numbers as arguments. There's no strict definition for what the multivalue ABI is at this time, so the main goal is to just not crash for now.

Closes #70402
Closes #153567

This fixes a crash in Clang when the `experimental-mv` ABI is used on
WebAssembly targets in conjunction with complex numbers as arguments.
There's no strict definition for what the multivalue ABI is at this
time, so the main goal is to just not crash for now.

Closes llvm#70402
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category backend:WebAssembly clang:codegen IR generation bugs: mangling, exceptions, etc. labels May 29, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented May 29, 2026

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-webassembly

Author: Alex Crichton (alexcrichton)

Changes

This fixes a crash in Clang when the experimental-mv ABI is used on WebAssembly targets in conjunction with complex numbers as arguments. There's no strict definition for what the multivalue ABI is at this time, so the main goal is to just not crash for now.

Closes #70402


Full diff: https://github.com/llvm/llvm-project/pull/200514.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/WebAssembly.cpp (+12-8)
  • (modified) clang/test/CodeGen/WebAssembly/wasm-arguments.c (+10)
diff --git a/clang/lib/CodeGen/Targets/WebAssembly.cpp b/clang/lib/CodeGen/Targets/WebAssembly.cpp
index ebe996a4edd8d..71454982c4f82 100644
--- a/clang/lib/CodeGen/Targets/WebAssembly.cpp
+++ b/clang/lib/CodeGen/Targets/WebAssembly.cpp
@@ -115,16 +115,20 @@ ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
       return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
     // For the experimental multivalue ABI, fully expand all other aggregates
     if (Kind == WebAssemblyABIKind::ExperimentalMV) {
-      const auto *RD = Ty->castAsRecordDecl();
-      bool HasBitField = false;
-      for (auto *Field : RD->fields()) {
-        if (Field->isBitField()) {
-          HasBitField = true;
-          break;
+      if (Ty->getAs<ComplexType>())
+        return ABIArgInfo::getDirect();
+      const auto *RD = Ty->getAsRecordDecl();
+      if (RD) {
+        bool HasBitField = false;
+        for (auto *Field : RD->fields()) {
+          if (Field->isBitField()) {
+            HasBitField = true;
+            break;
+          }
         }
+        if (!HasBitField)
+          return ABIArgInfo::getExpand();
       }
-      if (!HasBitField)
-        return ABIArgInfo::getExpand();
     }
   }
 
diff --git a/clang/test/CodeGen/WebAssembly/wasm-arguments.c b/clang/test/CodeGen/WebAssembly/wasm-arguments.c
index a0914fc768809..4bb381ea7b89d 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-arguments.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-arguments.c
@@ -138,3 +138,13 @@ bitfield1 bitfield_ret(void) {
   bitfield1 baz;
   return baz;
 }
+
+// Complex numbers are expanded in parameter position for the multivalue
+// experimental ABI.
+
+// WEBASSEMBLY32: define void @complex_double(ptr
+// WEBASSEMBLY64: define void @complex_double(ptr
+// EXPERIMENTAL-MV: define void @complex_double(double {{.*}}, double {{.*}})
+void complex_double(_Complex double a) {
+  // ..
+}

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang-codegen

Author: Alex Crichton (alexcrichton)

Changes

This fixes a crash in Clang when the experimental-mv ABI is used on WebAssembly targets in conjunction with complex numbers as arguments. There's no strict definition for what the multivalue ABI is at this time, so the main goal is to just not crash for now.

Closes #70402


Full diff: https://github.com/llvm/llvm-project/pull/200514.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/WebAssembly.cpp (+12-8)
  • (modified) clang/test/CodeGen/WebAssembly/wasm-arguments.c (+10)
diff --git a/clang/lib/CodeGen/Targets/WebAssembly.cpp b/clang/lib/CodeGen/Targets/WebAssembly.cpp
index ebe996a4edd8d..71454982c4f82 100644
--- a/clang/lib/CodeGen/Targets/WebAssembly.cpp
+++ b/clang/lib/CodeGen/Targets/WebAssembly.cpp
@@ -115,16 +115,20 @@ ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
       return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
     // For the experimental multivalue ABI, fully expand all other aggregates
     if (Kind == WebAssemblyABIKind::ExperimentalMV) {
-      const auto *RD = Ty->castAsRecordDecl();
-      bool HasBitField = false;
-      for (auto *Field : RD->fields()) {
-        if (Field->isBitField()) {
-          HasBitField = true;
-          break;
+      if (Ty->getAs<ComplexType>())
+        return ABIArgInfo::getDirect();
+      const auto *RD = Ty->getAsRecordDecl();
+      if (RD) {
+        bool HasBitField = false;
+        for (auto *Field : RD->fields()) {
+          if (Field->isBitField()) {
+            HasBitField = true;
+            break;
+          }
         }
+        if (!HasBitField)
+          return ABIArgInfo::getExpand();
       }
-      if (!HasBitField)
-        return ABIArgInfo::getExpand();
     }
   }
 
diff --git a/clang/test/CodeGen/WebAssembly/wasm-arguments.c b/clang/test/CodeGen/WebAssembly/wasm-arguments.c
index a0914fc768809..4bb381ea7b89d 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-arguments.c
+++ b/clang/test/CodeGen/WebAssembly/wasm-arguments.c
@@ -138,3 +138,13 @@ bitfield1 bitfield_ret(void) {
   bitfield1 baz;
   return baz;
 }
+
+// Complex numbers are expanded in parameter position for the multivalue
+// experimental ABI.
+
+// WEBASSEMBLY32: define void @complex_double(ptr
+// WEBASSEMBLY64: define void @complex_double(ptr
+// EXPERIMENTAL-MV: define void @complex_double(double {{.*}}, double {{.*}})
+void complex_double(_Complex double a) {
+  // ..
+}

@alexcrichton
Copy link
Copy Markdown
Contributor Author

I've confirmed that this fixes the crash in #153567 as well

@dschuff dschuff merged commit bb180dd into llvm:main Jun 4, 2026
14 checks passed
@alexcrichton alexcrichton deleted the compelx-fix branch June 4, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:WebAssembly clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen crash with -mmultivalue -Xclang -target-abi -Xclang experimental-mv clang crashes when targetting wasm32 with experimental-mv abi

2 participants