[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)
Sudharsan Veeravalli via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 3 20:27:58 PDT 2024
https://github.com/svs-quic updated https://github.com/llvm/llvm-project/pull/97315
>From 3c744fe6111f0b6d24356a584f94c6d1cb273f7a Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli <quic_svs at quicinc.com>
Date: Mon, 1 Jul 2024 21:58:37 +0530
Subject: [PATCH 1/2] [RISCV] Handle empty structs/unions passing in C++
---
clang/lib/CodeGen/Targets/RISCV.cpp | 9 +++---
clang/test/CodeGen/RISCV/abi-empty-structs.c | 34 ++++++++++++++++++++
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index a4c5ec315b8df..f2add9351c03c 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -361,12 +361,13 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
CGCXXABI::RAA_DirectInMemory);
}
- // Ignore empty structs/unions.
- if (isEmptyRecord(getContext(), Ty, true))
- return ABIArgInfo::getIgnore();
-
uint64_t Size = getContext().getTypeSize(Ty);
+ // Ignore empty structs/unions whose size is zero. According to the calling
+ // convention empty structs/unions are required to be sized types in C++.
+ if (isEmptyRecord(getContext(), Ty, true) && Size == 0)
+ return ABIArgInfo::getIgnore();
+
// Pass floating point values via FPRs if possible.
if (IsFixed && Ty->isFloatingType() && !Ty->isComplexType() &&
FLen >= Size && ArgFPRsLeft) {
diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c b/clang/test/CodeGen/RISCV/abi-empty-structs.c
index c48a2891627d4..877ed4962d4e8 100644
--- a/clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -167,6 +167,40 @@ struct s9 {
//
void test_s9(struct s9 a) {}
+struct s10 { };
+// CHECK-C-LABEL: define dso_local void @test_s10
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C: entry:
+//
+// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s103s10
+// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX: entry:
+//
+// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s103s10
+// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX: entry:
+//
+struct s10 test_s10(struct s10 a) {
+ return a;
+}
+
+struct s11 { int : 0; };
+// CHECK-C-LABEL: define dso_local void @test_s11
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C: entry:
+//
+// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s113s11
+// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX: entry:
+//
+// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s113s11
+// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX: entry:
+//
+struct s11 test_s11(struct s11 a) {
+ return a;
+}
+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
// CHECK32-C: {{.*}}
// CHECK64-C: {{.*}}
>From 004881e8b3453532bd5253e36a7c75b125784eda Mon Sep 17 00:00:00 2001
From: Sudharsan Veeravalli <quic_svs at quicinc.com>
Date: Thu, 4 Jul 2024 08:57:37 +0530
Subject: [PATCH 2/2] Add test case
---
clang/test/CodeGen/RISCV/abi-empty-structs.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c b/clang/test/CodeGen/RISCV/abi-empty-structs.c
index 877ed4962d4e8..fd119fbda046d 100644
--- a/clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -201,6 +201,19 @@ struct s11 test_s11(struct s11 a) {
return a;
}
+struct s12 {int x[0];};
+// CHECK-C-LABEL: define dso_local void @test_s12
+// CHECK-C-SAME: () #[[ATTR0]] {
+// CHECK-C: entry:
+//
+// CHECK-CXX-LABEL: define dso_local void @_Z8test_s123s12
+// CHECK-CXX-SAME: () #[[ATTR0]] {
+// CHECK-CXX: entry:
+//
+struct s12 test_s12(struct s12 a) {
+ return a;
+}
+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
// CHECK32-C: {{.*}}
// CHECK64-C: {{.*}}
More information about the cfe-commits
mailing list