diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1732,13 +1732,26 @@ verifyAttributeTypes(Attrs, V); - for (Attribute Attr : Attrs) + for (Attribute Attr : Attrs) { Assert(Attr.isStringAttribute() || Attribute::canUseAsParamAttr(Attr.getKindAsEnum()), "Attribute '" + Attr.getAsString() + "' does not apply to parameters", V); + if (Attr.hasAttribute(Attribute::Alignment)) { + Align AttrAlign = Attr.getAlignment().valueOrOne(); + // 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 + Align MaxAlign(1 << 15); + Assert(AttrAlign < MaxAlign, + "Attribute '" + Attr.getAsString() + "' exceed the max size 2^14", + V); + } + } + if (Attrs.hasAttribute(Attribute::ImmArg)) { Assert(Attrs.getNumAttributes() == 1, "Attribute 'immarg' is incompatible with other attributes", V); diff --git a/llvm/test/Verifier/param-attr-align.ll b/llvm/test/Verifier/param-attr-align.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Verifier/param-attr-align.ll @@ -0,0 +1,11 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +; CHECK: Attribute 'align 32768' exceed the max size 2^14 +define dso_local void @foo(i8* %p) { +entry: + %p1 = bitcast i8* %p to <8 x float>* + call void @bar(<8 x float>* noundef byval(<8 x float>) align 32768 %p1) + ret void +} + +declare dso_local void @bar(<8 x float>* %p)