[llvm] 650fbd5 - Verifier: Fix assert when verifying non-pointer byval or preallocated
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 20 17:09:04 PST 2020
Author: Matt Arsenault
Date: 2020-11-20T20:08:43-05:00
New Revision: 650fbd569a34960944d20d02b578e9be860453a7
URL: https://github.com/llvm/llvm-project/commit/650fbd569a34960944d20d02b578e9be860453a7
DIFF: https://github.com/llvm/llvm-project/commit/650fbd569a34960944d20d02b578e9be860453a7.diff
LOG: Verifier: Fix assert when verifying non-pointer byval or preallocated
This would fail on a cast<PointerType> when verifying the attribute if
these attributes were incorrectly used with a non-pointer type.
Added:
Modified:
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/byval-1.ll
llvm/test/Verifier/preallocated-invalid.ll
llvm/test/Verifier/sret.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 737cbb910f10..eda923da8df8 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1754,17 +1754,6 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
"'noinline and alwaysinline' are incompatible!",
V);
- if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) {
- Assert(Attrs.getByValType() == cast<PointerType>(Ty)->getElementType(),
- "Attribute 'byval' type does not match parameter!", V);
- }
-
- if (Attrs.hasAttribute(Attribute::Preallocated)) {
- Assert(Attrs.getPreallocatedType() ==
- cast<PointerType>(Ty)->getElementType(),
- "Attribute 'preallocated' type does not match parameter!", V);
- }
-
AttrBuilder IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty);
Assert(!AttrBuilder(Attrs).overlaps(IncompatibleAttrs),
"Wrong types for attribute: " +
@@ -1792,6 +1781,16 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
Assert(Attrs.getByRefType() == PTy->getElementType(),
"Attribute 'byref' type does not match parameter!", V);
}
+
+ if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) {
+ Assert(Attrs.getByValType() == PTy->getElementType(),
+ "Attribute 'byval' type does not match parameter!", V);
+ }
+
+ if (Attrs.hasAttribute(Attribute::Preallocated)) {
+ Assert(Attrs.getPreallocatedType() == PTy->getElementType(),
+ "Attribute 'preallocated' type does not match parameter!", V);
+ }
} else {
Assert(!Attrs.hasAttribute(Attribute::ByVal),
"Attribute 'byval' only applies to parameters with pointer type!",
diff --git a/llvm/test/Verifier/byval-1.ll b/llvm/test/Verifier/byval-1.ll
index 9d09a0ffb117..e2b4519b17cb 100644
--- a/llvm/test/Verifier/byval-1.ll
+++ b/llvm/test/Verifier/byval-1.ll
@@ -1,2 +1,5 @@
-; RUN: not llvm-as < %s > /dev/null 2>&1
-declare void @h(i32 byval %num)
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: Wrong types for attribute: inalloca nest noalias nocapture nonnull readnone readonly byref(i32) byval(i32) preallocated(i32) sret(i32) align 1 dereferenceable(1) dereferenceable_or_null(1)
+; CHECK-NEXT: void (i32)* @h
+declare void @h(i32 byval(i32) %num)
diff --git a/llvm/test/Verifier/preallocated-invalid.ll b/llvm/test/Verifier/preallocated-invalid.ll
index 879d4ed8a24f..392937f677e9 100644
--- a/llvm/test/Verifier/preallocated-invalid.ll
+++ b/llvm/test/Verifier/preallocated-invalid.ll
@@ -144,3 +144,7 @@ define void @teardown_token_not_from_setup() {
call void @llvm.call.preallocated.teardown(token %cs)
ret void
}
+
+; CHECK: Wrong types for attribute:
+; CHECK-NEXT: void (i32)* @not_pointer
+declare void @not_pointer(i32 preallocated(i32))
diff --git a/llvm/test/Verifier/sret.ll b/llvm/test/Verifier/sret.ll
index 38187ef4c96d..54e0d5b54d22 100644
--- a/llvm/test/Verifier/sret.ll
+++ b/llvm/test/Verifier/sret.ll
@@ -5,3 +5,7 @@ declare void @a(i32* sret(i32) %a, i32* sret(i32) %b)
declare void @b(i32* %a, i32* %b, i32* sret(i32) %c)
; CHECK: Attribute 'sret' is not on first or second parameter!
+
+; CHECK: Wrong types for attribute:
+; CHECK-NEXT: void (i32)* @not_ptr
+declare void @not_ptr(i32 sret(i32) %x)
More information about the llvm-commits
mailing list