[clang] [clang][wasm] Resolve assertion errors caused by converting ComplexTy… (PR #70496)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 14 05:27:00 PST 2023


https://github.com/knightXun updated https://github.com/llvm/llvm-project/pull/70496

>From e0ce1bab37de863d32d5d2e9b97f8bc345ef9ad9 Mon Sep 17 00:00:00 2001
From: xuknight <badgangkiller at gmail.com>
Date: Sat, 28 Oct 2023 02:52:43 +0800
Subject: [PATCH 1/2] [clang][wasm] Resolve assertion errors caused by
 converting ComplexType to RecordType

When a function parameter is of the built-in Complex type in Clang,
the conversion from ComplexType to RecordType is not possible, resulting in a crash in Clang.
RecordType is a helper class for structs, unions, and classes.
---
 clang/lib/CodeGen/Targets/WebAssembly.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/WebAssembly.cpp b/clang/lib/CodeGen/Targets/WebAssembly.cpp
index bd332228ce5bbe..b3f6473eb9bc74 100644
--- a/clang/lib/CodeGen/Targets/WebAssembly.cpp
+++ b/clang/lib/CodeGen/Targets/WebAssembly.cpp
@@ -114,6 +114,9 @@ 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) {
+      if (Ty->getAs<ComplexType>()) {
+        return ABIArgInfo::getDirect();
+      }
       const RecordType *RT = Ty->getAs<RecordType>();
       assert(RT);
       bool HasBitField = false;

>From 9916e4e446f7e92f385ca49d6f0031f48350b767 Mon Sep 17 00:00:00 2001
From: knightXun <badgangkiller at gmail.com>
Date: Thu, 14 Dec 2023 21:25:14 +0800
Subject: [PATCH 2/2] add test case for pr70496

---
 clang/test/CodeGen/pr70496.c | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 clang/test/CodeGen/pr70496.c

diff --git a/clang/test/CodeGen/pr70496.c b/clang/test/CodeGen/pr70496.c
new file mode 100644
index 00000000000000..5075b1ae91a704
--- /dev/null
+++ b/clang/test/CodeGen/pr70496.c
@@ -0,0 +1,9 @@
+// RUN: %clang --target=wasm32 -mmultivalue -Xclang -target-abi -Xclang experimental-mv %s -Xclang -verify
+
+float crealf() { return 0;} // expected-no-diagnostics
+
+float cimagf() { return 0;} // expected-no-diagnostics
+
+float a(float _Complex b) { return 0;} // expected-no-diagnostics
+
+float b(float _Complex c, float _Complex d) { return 0;} // expected-no-diagnostics
\ No newline at end of file



More information about the cfe-commits mailing list