[PATCH] D91270: [Clang][CodeGen][RISCV] Fix hard float ABI test cases with empty struct

Luís Marques via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 08:27:18 PST 2020


luismarques created this revision.
luismarques added reviewers: asb, lenary, rjmccall, efriedma.
Herald added subscribers: cfe-commits, frasercrmck, NickHung, evandro, apazos, sameer.abuasal, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar.
Herald added a project: clang.
luismarques requested review of this revision.

The code seemed not to account for the field 1 offset. This patch hopefully fixes that issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91270

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/riscv32-ilp32d-abi.cpp


Index: clang/test/CodeGen/riscv32-ilp32d-abi.cpp
===================================================================
--- clang/test/CodeGen/riscv32-ilp32d-abi.cpp
+++ clang/test/CodeGen/riscv32-ilp32d-abi.cpp
@@ -4,8 +4,7 @@
 struct empty_float2 { struct {}; float f; float g; };
 
 // CHECK: define float @_Z14f_empty_float212empty_float2(float %0, float %1)
-// FIXME: Extraneous padding before the second float
-// CHECK: { [4 x i8], float, [4 x i8], float }
+// CHECK: { [4 x i8], float, float }
 float f_empty_float2(empty_float2 a) {
     return a.g;
 }
@@ -13,8 +12,7 @@
 struct empty_double2 { struct {}; double f; double g; };
 
 // CHECK: define double @_Z15f_empty_double213empty_double2(double %0, double %1)
-// FIXME: Extraneous padding before the second double
-// CHECK: { [8 x i8], double, [8 x i8], double }
+// CHECK: { [8 x i8], double, double }
 double f_empty_double2(empty_double2 a) {
     return a.g;
 }
@@ -30,8 +28,7 @@
 struct empty_double_float { struct {}; double f; float g; };
 
 // CHECK: define double @_Z20f_empty_double_float18empty_double_float(double %0, float %1)
-// FIXME: Extraneous padding before the float
-// CHECK: { [8 x i8], double, [8 x i8], float }
+// CHECK: { [8 x i8], double, float }
 double f_empty_double_float(empty_double_float a) {
     return a.g;
 }
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10574,7 +10574,7 @@
     NeededArgFPRs++;
   else if (Field2Ty)
     NeededArgGPRs++;
-  return IsCandidate;
+  return true;
 }
 
 // Call getCoerceAndExpand for the two-element flattened struct described by
@@ -10600,15 +10600,16 @@
 
   CharUnits Field2Align =
       CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(Field2Ty));
-  CharUnits Field1Size =
-      CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty));
-  CharUnits Field2OffNoPadNoPack = Field1Size.alignTo(Field2Align);
+  CharUnits Field1EffectiveSize =
+      CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty)) +
+      Field1Off;
+  CharUnits Field2OffNoPadNoPack = Field1EffectiveSize.alignTo(Field2Align);
 
   CharUnits Padding = CharUnits::Zero();
   if (Field2Off > Field2OffNoPadNoPack)
     Padding = Field2Off - Field2OffNoPadNoPack;
-  else if (Field2Off != Field2Align && Field2Off > Field1Size)
-    Padding = Field2Off - Field1Size;
+  else if (Field2Off != Field2Align && Field2Off > Field1EffectiveSize)
+    Padding = Field2Off - Field1EffectiveSize;
 
   bool IsPacked = !Field2Off.isMultipleOf(Field2Align);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91270.304526.patch
Type: text/x-patch
Size: 2637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201111/c0b5026c/attachment.bin>


More information about the cfe-commits mailing list