[PATCH] D121898: [Verifier] Verify parameter alignment.
LuoYuanke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 21 23:19:05 PDT 2022
LuoYuanke updated this revision to Diff 417196.
LuoYuanke added a comment.
Rebase and have constant for parameter max alignment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121898/new/
https://reviews.llvm.org/D121898
Files:
llvm/include/llvm/CodeGen/TargetCallingConv.h
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/param-align.ll
llvm/test/Verifier/param-ret-align.ll
Index: llvm/test/Verifier/param-ret-align.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/param-ret-align.ll
@@ -0,0 +1,10 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: Incorrect alignment of return type to called function!
+define dso_local void @foo() {
+entry:
+ call <8192 x float> @bar()
+ ret void
+}
+
+declare dso_local <8192 x float> @bar()
Index: llvm/test/Verifier/param-align.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/param-align.ll
@@ -0,0 +1,10 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: Incorrect alignment of argument passed to called function!
+define dso_local void @foo(<8192 x float> noundef %vec) {
+entry:
+ call void @bar(<8192 x float> %vec)
+ ret void
+}
+
+declare dso_local void @bar(<8192 x float>)
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -279,6 +279,12 @@
class Verifier : public InstVisitor<Verifier>, VerifierSupport {
friend class InstVisitor<Verifier>;
+ // ISD::ArgFlagsTy::MemAlign only have 4 bits for alignment, so
+ // the alignment size should not exceed 2^15. Since encode(Align)
+ // would plus the shift value by 1, the alignment size should
+ // not exceed 2^14, otherwise it can NOT be properly lowered
+ // in backend.
+ static constexpr unsigned ParamMaxAlignment = 1 << 14;
DominatorTree DT;
/// When verifying a basic block, keep track of all of the
@@ -3143,6 +3149,21 @@
Assert(verifyAttributeCount(Attrs, Call.arg_size()),
"Attribute after last parameter!", Call);
+ auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) {
+ if (!Ty->isSized())
+ return;
+ Align ABIAlign = DL.getABITypeAlign(Ty);
+ Align MaxAlign(ParamMaxAlignment);
+ Assert(ABIAlign < MaxAlign,
+ "Incorrect alignment of " + Message + " to called function!", Call);
+ };
+
+ VerifyTypeAlign(FTy->getReturnType(), "return type");
+ for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
+ Type *Ty = FTy->getParamType(i);
+ VerifyTypeAlign(Ty, "argument passed");
+ }
+
Function *Callee =
dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
bool IsIntrinsic = Callee && Callee->isIntrinsic();
Index: llvm/include/llvm/CodeGen/TargetCallingConv.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetCallingConv.h
+++ llvm/include/llvm/CodeGen/TargetCallingConv.h
@@ -46,7 +46,8 @@
unsigned IsHvaStart : 1; ///< HVA structure start
unsigned IsSecArgPass : 1; ///< Second argument
unsigned MemAlign : 4; ///< Log 2 of alignment when arg is passed in memory
- ///< (including byval/byref)
+ ///< (including byval/byref). The max alignment is
+ ///< verified in IR verification.
unsigned OrigAlign : 5; ///< Log 2 of original alignment
unsigned IsInConsecutiveRegsLast : 1;
unsigned IsInConsecutiveRegs : 1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121898.417196.patch
Type: text/x-patch
Size: 3197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220322/175468e3/attachment.bin>
More information about the llvm-commits
mailing list