[clang] 9b38e2e - [SystemZ] Fix C++ ABI for passing args of structs containing zero width bitfield.

Jonas Paulsson via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 08:17:22 PDT 2022


Author: Jonas Paulsson
Date: 2022-04-26T17:16:14+02:00
New Revision: 9b38e2efa0f0c819ec696d13731ac1ce08f81930

URL: https://github.com/llvm/llvm-project/commit/9b38e2efa0f0c819ec696d13731ac1ce08f81930
DIFF: https://github.com/llvm/llvm-project/commit/9b38e2efa0f0c819ec696d13731ac1ce08f81930.diff

LOG: [SystemZ] Fix C++ ABI for passing args of structs containing zero width bitfield.

A struct like { float a; int :0; } should per the SystemZ ABI be passed in a
GPR, but to match a bug in GCC it has been passed in an FPR (see 759449c).

GCC has now corrected the C++ ABI for this case, and this patch for clang
follows suit.

Reviewed By: Ulrich Weigand

Differential Revision: https://reviews.llvm.org/D122388

Added: 
    

Modified: 
    clang/lib/CodeGen/TargetInfo.cpp
    clang/test/CodeGen/SystemZ/systemz-abi.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index c5a031d5487cf..ecbb3505bb91c 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -7514,12 +7514,9 @@ QualType SystemZABIInfo::GetSingleElementType(QualType Ty) const {
 
     // Check the fields.
     for (const auto *FD : RD->fields()) {
-      // For compatibility with GCC, ignore empty bitfields in C++ mode.
       // Unlike isSingleElementStruct(), empty structure and array fields
       // do count.  So do anonymous bitfields that aren't zero-sized.
-      if (getContext().getLangOpts().CPlusPlus &&
-          FD->isZeroLengthBitField(getContext()))
-        continue;
+
       // Like isSingleElementStruct(), ignore C++20 empty data members.
       if (FD->hasAttr<NoUniqueAddressAttr>() &&
           isEmptyRecord(getContext(), FD->getType(), true))

diff  --git a/clang/test/CodeGen/SystemZ/systemz-abi.cpp b/clang/test/CodeGen/SystemZ/systemz-abi.cpp
index 9a0b2e39c6070..a76bba3561b44 100644
--- a/clang/test/CodeGen/SystemZ/systemz-abi.cpp
+++ b/clang/test/CodeGen/SystemZ/systemz-abi.cpp
@@ -15,12 +15,10 @@ class agg_double_class pass_agg_double_class(class agg_double_class arg) { retur
 // SOFT-FLOAT-LABEL: define{{.*}} void @_Z21pass_agg_double_class16agg_double_class(%class.agg_double_class* noalias sret(%class.agg_double_class) align 8 %{{.*}}, i64 %{{.*}})
 
 
-// For compatibility with GCC, this structure is passed in an FPR in C++,
-// but passed in a GPR in C (checked in systemz-abi.c).
-
+// This structure is passed in a GPR in C++ (and C, checked in systemz-abi.c).
 struct agg_float_cpp { float a; int : 0; };
 struct agg_float_cpp pass_agg_float_cpp(struct agg_float_cpp arg) { return arg; }
-// CHECK-LABEL: define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, float %{{.*}})
+// CHECK-LABEL: define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 // SOFT-FLOAT-LABEL:  define{{.*}} void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret(%struct.agg_float_cpp) align 4 %{{.*}}, i32 %{{.*}})
 
 


        


More information about the cfe-commits mailing list