Skip to content

Commit fa8f5bf

Browse files
committed
[Clang][CodeGen][RISCV] Fix hard float ABI test cases with empty struct
The code seemed not to account for the field 1 offset. Differential Revision: https://reviews.llvm.org/D91270
1 parent ca93f9a commit fa8f5bf

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10520,7 +10520,7 @@ bool RISCVABIInfo::detectFPCCEligibleStruct(QualType Ty, llvm::Type *&Field1Ty,
1052010520
NeededArgFPRs++;
1052110521
else if (Field2Ty)
1052210522
NeededArgGPRs++;
10523-
return IsCandidate;
10523+
return true;
1052410524
}
1052510525

1052610526
// Call getCoerceAndExpand for the two-element flattened struct described by
@@ -10546,15 +10546,15 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
1054610546

1054710547
CharUnits Field2Align =
1054810548
CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(Field2Ty));
10549-
CharUnits Field1Size =
10549+
CharUnits Field1End = Field1Off +
1055010550
CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty));
10551-
CharUnits Field2OffNoPadNoPack = Field1Size.alignTo(Field2Align);
10551+
CharUnits Field2OffNoPadNoPack = Field1End.alignTo(Field2Align);
1055210552

1055310553
CharUnits Padding = CharUnits::Zero();
1055410554
if (Field2Off > Field2OffNoPadNoPack)
1055510555
Padding = Field2Off - Field2OffNoPadNoPack;
10556-
else if (Field2Off != Field2Align && Field2Off > Field1Size)
10557-
Padding = Field2Off - Field1Size;
10556+
else if (Field2Off != Field2Align && Field2Off > Field1End)
10557+
Padding = Field2Off - Field1End;
1055810558

1055910559
bool IsPacked = !Field2Off.isMultipleOf(Field2Align);
1056010560

clang/test/CodeGen/riscv32-ilp32d-abi.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
struct empty_float2 { struct {}; float f; float g; };
55

66
// CHECK: define float @_Z14f_empty_float212empty_float2(float %0, float %1)
7-
// FIXME: Extraneous padding before the second float
8-
// CHECK: { [4 x i8], float, [4 x i8], float }
7+
// CHECK: { [4 x i8], float, float }
98
float f_empty_float2(empty_float2 a) {
109
return a.g;
1110
}
1211

1312
struct empty_double2 { struct {}; double f; double g; };
1413

1514
// CHECK: define double @_Z15f_empty_double213empty_double2(double %0, double %1)
16-
// FIXME: Extraneous padding before the second double
17-
// CHECK: { [8 x i8], double, [8 x i8], double }
15+
// CHECK: { [8 x i8], double, double }
1816
double f_empty_double2(empty_double2 a) {
1917
return a.g;
2018
}
@@ -30,8 +28,7 @@ double f_empty_float_double(empty_float_double a) {
3028
struct empty_double_float { struct {}; double f; float g; };
3129

3230
// CHECK: define double @_Z20f_empty_double_float18empty_double_float(double %0, float %1)
33-
// FIXME: Extraneous padding before the float
34-
// CHECK: { [8 x i8], double, [8 x i8], float }
31+
// CHECK: { [8 x i8], double, float }
3532
double f_empty_double_float(empty_double_float a) {
3633
return a.g;
3734
}

0 commit comments

Comments
 (0)