[llvm] 1fd118f - Verify parameter alignment attribute

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 26 18:13:44 PDT 2022


Author: Luo, Yuanke
Date: 2022-03-27T09:03:22+08:00
New Revision: 1fd118ffc4b8d72d372de0fdbc5024ecf3dd3948

URL: https://github.com/llvm/llvm-project/commit/1fd118ffc4b8d72d372de0fdbc5024ecf3dd3948
DIFF: https://github.com/llvm/llvm-project/commit/1fd118ffc4b8d72d372de0fdbc5024ecf3dd3948.diff

LOG: Verify parameter alignment attribute

In DAGISel, the parameter alignment only have 4 bits to hold the value.
The encode(alignment) would plus the value by 1, so the max aligment that
ISel can support is 2^14. This patch verify align attribute for parameter.

Differential Revision: https://reviews.llvm.org/D122130

Added: 
    llvm/test/Verifier/param-attr-align.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 94f7ccc4b6785..bcaa53bdfc6bb 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1819,6 +1819,12 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
 
   if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {
     if (Attrs.hasAttribute(Attribute::ByVal)) {
+      if (Attrs.hasAttribute(Attribute::Alignment)) {
+        Align AttrAlign = Attrs.getAlignment().valueOrOne();
+        Align MaxAlign(ParamMaxAlignment);
+        Assert(AttrAlign <= MaxAlign,
+               "Attribute 'align' exceed the max size 2^14", V);
+      }
       SmallPtrSet<Type *, 4> Visited;
       Assert(Attrs.getByValType()->isSized(&Visited),
              "Attribute 'byval' does not support unsized types!", V);
@@ -3154,7 +3160,7 @@ void Verifier::visitCallBase(CallBase &Call) {
       return;
     Align ABIAlign = DL.getABITypeAlign(Ty);
     Align MaxAlign(ParamMaxAlignment);
-    Assert(ABIAlign < MaxAlign,
+    Assert(ABIAlign <= MaxAlign,
            "Incorrect alignment of " + Message + " to called function!", Call);
   };
 

diff  --git a/llvm/test/Verifier/param-attr-align.ll b/llvm/test/Verifier/param-attr-align.ll
new file mode 100644
index 0000000000000..eb9ad0619feb9
--- /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' 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)


        


More information about the llvm-commits mailing list