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

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 14 06:07:38 PST 2023


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

>From e09d1b428f0c3836e2b92df3c994375f4c946302 Mon Sep 17 00:00:00 2001
From: xuknight <badgangkiller at gmail.com>
Date: Sat, 28 Oct 2023 02:52:43 +0800
Subject: [PATCH] [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 +++
 clang/test/CodeGen/pr70496.c              | 9 +++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 clang/test/CodeGen/pr70496.c

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;
diff --git a/clang/test/CodeGen/pr70496.c b/clang/test/CodeGen/pr70496.c
new file mode 100644
index 00000000000000..9eeef7b254d8cb
--- /dev/null
+++ b/clang/test/CodeGen/pr70496.c
@@ -0,0 +1,9 @@
+// RUN: %clang --target=wasm32 -mmultivalue -Xclang -target-abi -Xclang experimental-mv %s -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