[clang] [AArch64ABI] Don't pass small types with padding as wide ints. (WIP) (PR #116615)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 05:45:44 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 20d8f8ca1a9de3506c7cad55abcea501a0c57afa f983323a596bf5d777ad0316853044cedf02a91a --extensions cpp -- clang/test/CodeGen/AArch64/small-types-with-padding.cpp clang/lib/AST/RecordLayoutBuilder.cpp clang/lib/CodeGen/Targets/AArch64.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 702c11d1e5..6734b350c3 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2450,7 +2450,7 @@ static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD) {
// mode; fortunately, that is true because we want to assign
// consistently semantics to the type-traits intrinsics (or at
// least as many of them as possible).
- return false; //RD->isTrivial() && RD->isCXX11StandardLayout();
+ return false; // RD->isTrivial() && RD->isCXX11StandardLayout();
}
llvm_unreachable("bad tail-padding use kind");
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp b/clang/lib/CodeGen/Targets/AArch64.cpp
index 657db473fe..dc64b51098 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -484,23 +484,28 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadicFn,
return getNaturalAlignIndirect(Ty, /*ByVal=*/false);
}
-static std::pair<unsigned, unsigned> computePadding(QualType T, ASTContext &Ctx) {
- unsigned Padding = 0;
- unsigned TailPadding = 0;
- if (auto *RD = T->getAs<RecordType>()) {
- for (auto I = RD->getDecl()->field_begin(), End = RD->getDecl()->field_end(); I != End; ++I) {
- QualType FieldTy = I->getType();
- if (auto *ET = FieldTy->getAs<ElaboratedType>())
- FieldTy = ET->getNamedType();
- if (auto *RD2 = FieldTy->getAs<RecordType>()) {
- auto &Layout = Ctx.getASTRecordLayout(RD2->getDecl());
- auto[SubPadding, SubTailPadding] = computePadding(I->getType(), Ctx);
- TailPadding = Ctx.toBits(Layout.getSize() - Layout.getDataSize()) +SubTailPadding;
- Padding += Ctx.toBits(Layout.getSize() - Layout.getDataSize()) + SubPadding;
- }
+static std::pair<unsigned, unsigned> computePadding(QualType T,
+ ASTContext &Ctx) {
+ unsigned Padding = 0;
+ unsigned TailPadding = 0;
+ if (auto *RD = T->getAs<RecordType>()) {
+ for (auto I = RD->getDecl()->field_begin(),
+ End = RD->getDecl()->field_end();
+ I != End; ++I) {
+ QualType FieldTy = I->getType();
+ if (auto *ET = FieldTy->getAs<ElaboratedType>())
+ FieldTy = ET->getNamedType();
+ if (auto *RD2 = FieldTy->getAs<RecordType>()) {
+ auto &Layout = Ctx.getASTRecordLayout(RD2->getDecl());
+ auto [SubPadding, SubTailPadding] = computePadding(I->getType(), Ctx);
+ TailPadding = Ctx.toBits(Layout.getSize() - Layout.getDataSize()) +
+ SubTailPadding;
+ Padding +=
+ Ctx.toBits(Layout.getSize() - Layout.getDataSize()) + SubPadding;
}
}
- return {Padding, TailPadding};
+ }
+ return {Padding, TailPadding};
}
ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType RetTy,
@@ -563,7 +568,10 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType RetTy,
// Aggregates <= 16 bytes are returned directly in registers or on the stack.
if (Size <= 128) {
auto [Padding, TailPadding] = computePadding(RetTy, getContext());
- // If the type contains any padding, be careful not to lower to wide types that may mix data and padding bits. E.g. using i64 for a type that has 32 bits of data and 32 bits of padding means loading the uninitialized padding bits together with data bits poisons the resulting wide type.
+ // If the type contains any padding, be careful not to lower to wide types
+ // that may mix data and padding bits. E.g. using i64 for a type that has 32
+ // bits of data and 32 bits of padding means loading the uninitialized
+ // padding bits together with data bits poisons the resulting wide type.
if (Padding > 0) {
if (Padding == TailPadding && (Size - TailPadding) % 8 == 0) {
llvm::Type *BaseTy = llvm::Type::getInt8Ty(getVMContext());
``````````
</details>
https://github.com/llvm/llvm-project/pull/116615
More information about the cfe-commits
mailing list