diff options
author | Eli Friedman <efriedma@quicinc.com> | 2024-07-18 12:32:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-18 12:32:13 -0700 |
commit | 82cca0c77e935b4972c31745d94edef616970b6c (patch) | |
tree | d30101ec5a279995f5efcb118ec4c27df321e6de /llvm/lib/IR/Verifier.cpp | |
parent | e2c3cd7f3d0cd40bd8506ab305573d61a1ae25d9 (diff) | |
download | llvm-82cca0c77e935b4972c31745d94edef616970b6c.zip llvm-82cca0c77e935b4972c31745d94edef616970b6c.tar.gz llvm-82cca0c77e935b4972c31745d94edef616970b6c.tar.bz2 |
[IR] Unify max alignment for arguments with generic max align. (#99257)
The 2^14 limit was completely arbitrary; the generic limit is still
arbitrary, but at least it's the same arbitrary limit as everything
else.
While I'm here, also add a verifier check for the ByValOrByRefSize.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 75a53c1..c5c4076 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -324,13 +324,6 @@ namespace { 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 @@ -2021,31 +2014,43 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, } if (isa<PointerType>(Ty)) { + if (Attrs.hasAttribute(Attribute::Alignment)) { + Align AttrAlign = Attrs.getAlignment().valueOrOne(); + Check(AttrAlign.value() <= Value::MaximumAlignment, + "huge alignment values are unsupported", V); + } if (Attrs.hasAttribute(Attribute::ByVal)) { - if (Attrs.hasAttribute(Attribute::Alignment)) { - Align AttrAlign = Attrs.getAlignment().valueOrOne(); - Align MaxAlign(ParamMaxAlignment); - Check(AttrAlign <= MaxAlign, - "Attribute 'align' exceed the max size 2^14", V); - } SmallPtrSet<Type *, 4> Visited; Check(Attrs.getByValType()->isSized(&Visited), "Attribute 'byval' does not support unsized types!", V); + Check(DL.getTypeAllocSize(Attrs.getByValType()).getKnownMinValue() < + (1ULL << 32), + "huge 'byval' arguments are unsupported", V); } if (Attrs.hasAttribute(Attribute::ByRef)) { SmallPtrSet<Type *, 4> Visited; Check(Attrs.getByRefType()->isSized(&Visited), "Attribute 'byref' does not support unsized types!", V); + Check(DL.getTypeAllocSize(Attrs.getByRefType()).getKnownMinValue() < + (1ULL << 32), + "huge 'byref' arguments are unsupported", V); } if (Attrs.hasAttribute(Attribute::InAlloca)) { SmallPtrSet<Type *, 4> Visited; Check(Attrs.getInAllocaType()->isSized(&Visited), "Attribute 'inalloca' does not support unsized types!", V); + Check(DL.getTypeAllocSize(Attrs.getInAllocaType()).getKnownMinValue() < + (1ULL << 32), + "huge 'inalloca' arguments are unsupported", V); } if (Attrs.hasAttribute(Attribute::Preallocated)) { SmallPtrSet<Type *, 4> Visited; Check(Attrs.getPreallocatedType()->isSized(&Visited), "Attribute 'preallocated' does not support unsized types!", V); + Check( + DL.getTypeAllocSize(Attrs.getPreallocatedType()).getKnownMinValue() < + (1ULL << 32), + "huge 'preallocated' arguments are unsupported", V); } } @@ -3511,12 +3516,15 @@ void Verifier::visitCallBase(CallBase &Call) { "not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.", Call); + // Disallow passing/returning values with alignment higher than we can + // represent. + // FIXME: Consider making DataLayout cap the alignment, so this isn't + // necessary. auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) { if (!Ty->isSized()) return; Align ABIAlign = DL.getABITypeAlign(Ty); - Align MaxAlign(ParamMaxAlignment); - Check(ABIAlign <= MaxAlign, + Check(ABIAlign.value() <= Value::MaximumAlignment, "Incorrect alignment of " + Message + " to called function!", Call); }; |