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_...@quicinc.com> Date: Mon, 1 Jul 2024 21:58:37 +0530 Subject: [PATCH 1/4] [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_...@quicinc.com> Date: Thu, 4 Jul 2024 08:57:37 +0530 Subject: [PATCH 2/4] 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: {{.*}} >From d6b523c859218ca1c982b289de269bc828087701 Mon Sep 17 00:00:00 2001 From: Sudharsan Veeravalli <quic_...@quicinc.com> Date: Sat, 6 Jul 2024 09:54:49 +0530 Subject: [PATCH 3/4] Change check and add release notes --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/CodeGen/Targets/RISCV.cpp | 3 ++- clang/test/CodeGen/RISCV/abi-empty-structs.c | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 90c2469c1c89a..53ff40b1afef7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1061,6 +1061,7 @@ RISC-V Support - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t types. - Profile names in ``-march`` option are now supported. +- Passing empty structs/unions as arguments in C++ is now handled correctly. The behavior is similar to GCC's. CUDA/HIP Language Changes ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index f2add9351c03c..d1b84fd1724d7 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -365,7 +365,8 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed, // 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) + if (isEmptyRecord(getContext(), Ty, true) && + !getContext().getLangOpts().CPlusPlus) return ABIArgInfo::getIgnore(); // Pass floating point values via FPRs if possible. diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c b/clang/test/CodeGen/RISCV/abi-empty-structs.c index fd119fbda046d..5a54838060368 100644 --- a/clang/test/CodeGen/RISCV/abi-empty-structs.c +++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c @@ -206,9 +206,13 @@ struct s12 {int x[0];}; // CHECK-C-SAME: () #[[ATTR0]] { // CHECK-C: entry: // -// CHECK-CXX-LABEL: define dso_local void @_Z8test_s123s12 -// CHECK-CXX-SAME: () #[[ATTR0]] { -// CHECK-CXX: entry: +// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s123s12 +// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] { +// CHECK32-CXX: entry: +// +// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s123s12 +// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] { +// CHECK64-CXX: entry: // struct s12 test_s12(struct s12 a) { return a; >From 8fb4600262db32243e17cddebfac7db873adbddb Mon Sep 17 00:00:00 2001 From: Sudharsan Veeravalli <quic_...@quicinc.com> Date: Mon, 8 Jul 2024 13:52:57 +0530 Subject: [PATCH 4/4] Fix check and modify test --- clang/lib/CodeGen/Targets/RISCV.cpp | 3 +-- clang/test/CodeGen/RISCV/abi-empty-structs.c | 22 ++++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index d1b84fd1724d7..f2add9351c03c 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -365,8 +365,7 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed, // 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) && - !getContext().getLangOpts().CPlusPlus) + if (isEmptyRecord(getContext(), Ty, true) && Size == 0) return ABIArgInfo::getIgnore(); // Pass floating point values via FPRs if possible. diff --git a/clang/test/CodeGen/RISCV/abi-empty-structs.c b/clang/test/CodeGen/RISCV/abi-empty-structs.c index 5a54838060368..5157165787fcb 100644 --- a/clang/test/CodeGen/RISCV/abi-empty-structs.c +++ b/clang/test/CodeGen/RISCV/abi-empty-structs.c @@ -202,20 +202,24 @@ struct s11 test_s11(struct s11 a) { } struct s12 {int x[0];}; -// CHECK-C-LABEL: define dso_local void @test_s12 -// CHECK-C-SAME: () #[[ATTR0]] { -// CHECK-C: entry: +// CHECK32-C-LABEL: define dso_local i32 @test_s12 +// CHECK32-C-SAME: (i32 noundef [[I1:%.*]], i32 noundef [[I2:%.*]]) #[[ATTR0]] { +// CHECK32-C: entry: // -// CHECK32-CXX-LABEL: define dso_local i32 @_Z8test_s123s12 -// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] { +// CHECK64-C-LABEL: define dso_local signext i32 @test_s12 +// CHECK64-C-SAME: (i32 noundef signext [[I1:%.*]], i32 noundef signext [[I2:%.*]]) #[[ATTR0]] { +// CHECK64-C: entry: +// +// CHECK32-CXX-LABEL: define dso_local noundef i32 @_Z8test_s12i3s12i +// CHECK32-CXX-SAME: (i32 noundef [[I1:%.*]], i32 noundef [[I2:%.*]]) #[[ATTR0]] { // CHECK32-CXX: entry: // -// CHECK64-CXX-LABEL: define dso_local i64 @_Z8test_s123s12 -// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] { +// CHECK64-CXX-LABEL: define dso_local noundef signext i32 @_Z8test_s12i3s12i +// CHECK64-CXX-SAME: (i32 noundef signext [[I1:%.*]], i32 noundef signext [[I2:%.*]]) #[[ATTR0]] { // CHECK64-CXX: entry: // -struct s12 test_s12(struct s12 a) { - return a; +int test_s12(int32_t i1, struct s12 a, int32_t i2) { + return i2; } //// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits