forked from OSchip/llvm-project
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.
This commit is contained in:
parent
1d1234b2a4
commit
650fbd569a
|
@ -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!",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue