[PATCH] D131677: [clang][RISCV][WIP] Fix incorrect ABI lowering for inherited structs with hard-float ABIs
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 06:59:37 PDT 2022
asb created this revision.
Herald added subscribers: wingo, sunshaoce, pmatos, VincentWu, luke957, StephenFan, vkmr, evandro, luismarques, sameer.abuasal, s.egerton, Jim, benna, psnobl, rogfer01, shiva0217, kito-cheng, simoncook, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD.
The hard float ABIs have a rule that if a flattened struct contains either a single fp value, or an int+fp, or fp+fp then it may be passed in a pair of registers (if sufficient GPRs+FPRs are available). detectFPCCEligibleStruct and the helper it calls, detectFPCCEligibleStructHelper examine the type of the argument/return value to determine if it complies with the requirements for this ABI rule.
As reported in bug #57084 <https://github.com/llvm/llvm-project/issues/57084>, this logic produces incorrect results for C++ structs that inherit from other structs. This is because only the fields of the struct were examined, but enumerating `RD->fields` misses any fields in inherited C++ structs. This patch corrects that issue by adding appropriate logic to enumerate any included base structs.
WIP as upstream-quality tests not yet implemented. Sharing early as this is a very nasty bug that we should fix ASAP, and it would be good to avoid duplicated effort.
https://reviews.llvm.org/D131677
Files:
clang/lib/CodeGen/TargetInfo.cpp
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10979,6 +10979,15 @@
// Unions aren't eligible unless they're empty (which is caught above).
if (RD->isUnion())
return false;
+ // If this is a C++ record, check the bases first.
+ if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
+ for (const CXXBaseSpecifier &B : CXXRD->bases()) {
+ bool Ret = detectFPCCEligibleStructHelper(
+ B.getType(), CurOff, Field1Ty, Field1Off, Field2Ty, Field2Off);
+ if (!Ret)
+ return false;
+ }
+ }
int ZeroWidthBitFieldCount = 0;
for (const FieldDecl *FD : RD->fields()) {
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131677.451840.patch
Type: text/x-patch
Size: 862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220811/0dc60d33/attachment.bin>
More information about the llvm-commits
mailing list