[PATCH] D122130: Verify parameter alignment attribute

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1fd118ffc4b8: Verify parameter alignment attribute (authored by LuoYuanke).

Changed prior to commit:
  https://reviews.llvm.org/D122130?vs=417190&id=418429#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122130/new/

https://reviews.llvm.org/D122130

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/param-attr-align.ll


Index: llvm/test/Verifier/param-attr-align.ll
===================================================================
--- /dev/null
+++ 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)
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1819,6 +1819,12 @@
 
   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 @@
       return;
     Align ABIAlign = DL.getABITypeAlign(Ty);
     Align MaxAlign(ParamMaxAlignment);
-    Assert(ABIAlign < MaxAlign,
+    Assert(ABIAlign <= MaxAlign,
            "Incorrect alignment of " + Message + " to called function!", Call);
   };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122130.418429.patch
Type: text/x-patch
Size: 1518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220327/cba5c9fc/attachment.bin>


More information about the llvm-commits mailing list