[PATCH] D105841: [Verifier] Check byval/etc type when comparing ABI attributes

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 12 13:35:41 PDT 2021


nikic created this revision.
nikic added a reviewer: rnk.
Herald added subscribers: dexonsmith, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For musttail calls, ABI attributes between the function and the musttail call must match. The current check discards the type of type attribute like byval, which means that it will consider `byval(i32)` and `byval(i64)` (or similar) as compatible.

I assume this is a leftover from before these attributes had a type argument. Ran into this while trying to tighten an assertion in AttrBuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105841

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/musttail-invalid.ll


Index: llvm/test/Verifier/musttail-invalid.ll
===================================================================
--- llvm/test/Verifier/musttail-invalid.ll
+++ llvm/test/Verifier/musttail-invalid.ll
@@ -46,6 +46,13 @@
   ret void
 }
 
+declare void @mismatched_byval_callee2(ptr byval(i32))
+define void @mismatched_byval2(ptr byval(i64) %a) {
+; CHECK: mismatched ABI impacting function attributes
+  musttail call void @mismatched_byval_callee2(ptr byval(i32) %a)
+  ret void
+}
+
 declare void @mismatched_inreg_callee(i32 inreg)
 define void @mismatched_inreg(i32 %a) {
 ; CHECK: mismatched ABI impacting function attributes
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3320,8 +3320,9 @@
       Attribute::ByRef};
   AttrBuilder Copy;
   for (auto AK : ABIAttrs) {
-    if (Attrs.hasParamAttribute(I, AK))
-      Copy.addAttribute(AK);
+    Attribute Attr = Attrs.getParamAttributes(I).getAttribute(AK);
+    if (Attr.isValid())
+      Copy.addAttribute(Attr);
   }
 
   // `align` is ABI-affecting only in combination with `byval` or `byref`.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105841.358052.patch
Type: text/x-patch
Size: 1166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210712/efeaee52/attachment.bin>


More information about the llvm-commits mailing list