Skip to content

Commit a4eaecf

Browse files
luismarqueststellar
authored andcommitted
[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 (cherry picked from commit fa8f5bf)
1 parent ba223fa commit a4eaecf

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
@@ -10490,7 +10490,7 @@ bool RISCVABIInfo::detectFPCCEligibleStruct(QualType Ty, llvm::Type *&Field1Ty,
1049010490
NeededArgFPRs++;
1049110491
else if (Field2Ty)
1049210492
NeededArgGPRs++;
10493-
return IsCandidate;
10493+
return true;
1049410494
}
1049510495

1049610496
// Call getCoerceAndExpand for the two-element flattened struct described by
@@ -10516,15 +10516,15 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
1051610516

1051710517
CharUnits Field2Align =
1051810518
CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(Field2Ty));
10519-
CharUnits Field1Size =
10519+
CharUnits Field1End = Field1Off +
1052010520
CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty));
10521-
CharUnits Field2OffNoPadNoPack = Field1Size.alignTo(Field2Align);
10521+
CharUnits Field2OffNoPadNoPack = Field1End.alignTo(Field2Align);
1052210522

1052310523
CharUnits Padding = CharUnits::Zero();
1052410524
if (Field2Off > Field2OffNoPadNoPack)
1052510525
Padding = Field2Off - Field2OffNoPadNoPack;
10526-
else if (Field2Off != Field2Align && Field2Off > Field1Size)
10527-
Padding = Field2Off - Field1Size;
10526+
else if (Field2Off != Field2Align && Field2Off > Field1End)
10527+
Padding = Field2Off - Field1End;
1052810528

1052910529
bool IsPacked = !Field2Off.isMultipleOf(Field2Align);
1053010530

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)