@@ -324,13 +324,6 @@ namespace {
324324
325325class Verifier : public InstVisitor <Verifier>, VerifierSupport {
326326 friend class InstVisitor <Verifier>;
327-
328- // ISD::ArgFlagsTy::MemAlign only have 4 bits for alignment, so
329- // the alignment size should not exceed 2^15. Since encode(Align)
330- // would plus the shift value by 1, the alignment size should
331- // not exceed 2^14, otherwise it can NOT be properly lowered
332- // in backend.
333- static constexpr unsigned ParamMaxAlignment = 1 << 14 ;
334327 DominatorTree DT;
335328
336329 // / When verifying a basic block, keep track of all of the
@@ -2021,31 +2014,43 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
20212014 }
20222015
20232016 if (isa<PointerType>(Ty)) {
2017+ if (Attrs.hasAttribute (Attribute::Alignment)) {
2018+ Align AttrAlign = Attrs.getAlignment ().valueOrOne ();
2019+ Check (AttrAlign.value () <= Value::MaximumAlignment,
2020+ " huge alignment values are unsupported" , V);
2021+ }
20242022 if (Attrs.hasAttribute (Attribute::ByVal)) {
2025- if (Attrs.hasAttribute (Attribute::Alignment)) {
2026- Align AttrAlign = Attrs.getAlignment ().valueOrOne ();
2027- Align MaxAlign (ParamMaxAlignment);
2028- Check (AttrAlign <= MaxAlign,
2029- " Attribute 'align' exceed the max size 2^14" , V);
2030- }
20312023 SmallPtrSet<Type *, 4 > Visited;
20322024 Check (Attrs.getByValType ()->isSized (&Visited),
20332025 " Attribute 'byval' does not support unsized types!" , V);
2026+ Check (DL.getTypeAllocSize (Attrs.getByValType ()).getKnownMinValue () <
2027+ (1ULL << 32 ),
2028+ " huge 'byval' arguments are unsupported" , V);
20342029 }
20352030 if (Attrs.hasAttribute (Attribute::ByRef)) {
20362031 SmallPtrSet<Type *, 4 > Visited;
20372032 Check (Attrs.getByRefType ()->isSized (&Visited),
20382033 " Attribute 'byref' does not support unsized types!" , V);
2034+ Check (DL.getTypeAllocSize (Attrs.getByRefType ()).getKnownMinValue () <
2035+ (1ULL << 32 ),
2036+ " huge 'byref' arguments are unsupported" , V);
20392037 }
20402038 if (Attrs.hasAttribute (Attribute::InAlloca)) {
20412039 SmallPtrSet<Type *, 4 > Visited;
20422040 Check (Attrs.getInAllocaType ()->isSized (&Visited),
20432041 " Attribute 'inalloca' does not support unsized types!" , V);
2042+ Check (DL.getTypeAllocSize (Attrs.getInAllocaType ()).getKnownMinValue () <
2043+ (1ULL << 32 ),
2044+ " huge 'inalloca' arguments are unsupported" , V);
20442045 }
20452046 if (Attrs.hasAttribute (Attribute::Preallocated)) {
20462047 SmallPtrSet<Type *, 4 > Visited;
20472048 Check (Attrs.getPreallocatedType ()->isSized (&Visited),
20482049 " Attribute 'preallocated' does not support unsized types!" , V);
2050+ Check (
2051+ DL.getTypeAllocSize (Attrs.getPreallocatedType ()).getKnownMinValue () <
2052+ (1ULL << 32 ),
2053+ " huge 'preallocated' arguments are unsupported" , V);
20492054 }
20502055 }
20512056
@@ -3511,12 +3516,15 @@ void Verifier::visitCallBase(CallBase &Call) {
35113516 " not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead." ,
35123517 Call);
35133518
3519+ // Disallow passing/returning values with alignment higher than we can
3520+ // represent.
3521+ // FIXME: Consider making DataLayout cap the alignment, so this isn't
3522+ // necessary.
35143523 auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) {
35153524 if (!Ty->isSized ())
35163525 return ;
35173526 Align ABIAlign = DL.getABITypeAlign (Ty);
3518- Align MaxAlign (ParamMaxAlignment);
3519- Check (ABIAlign <= MaxAlign,
3527+ Check (ABIAlign.value () <= Value::MaximumAlignment,
35203528 " Incorrect alignment of " + Message + " to called function!" , Call);
35213529 };
35223530
0 commit comments