diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1839,40 +1839,59 @@ V); if (PointerType *PTy = dyn_cast(Ty)) { - SmallPtrSet Visited; - if (!PTy->getElementType()->isSized(&Visited)) { - Assert(!Attrs.hasAttribute(Attribute::ByVal) && - !Attrs.hasAttribute(Attribute::ByRef) && - !Attrs.hasAttribute(Attribute::InAlloca) && - !Attrs.hasAttribute(Attribute::Preallocated), - "Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do not " - "support unsized types!", - V); - } - if (!isa(PTy->getElementType())) - Assert(!Attrs.hasAttribute(Attribute::SwiftError), - "Attribute 'swifterror' only applies to parameters " - "with pointer to pointer type!", - V); - - if (Attrs.hasAttribute(Attribute::ByRef)) { - Assert(Attrs.getByRefType() == PTy->getElementType(), - "Attribute 'byref' type does not match parameter!", V); - } + if (PTy->isOpaque()) { + if (Attrs.hasAttribute(Attribute::ByVal)) { + Assert(Attrs.getByValType()->isSized(), + "Attributes 'byval' does not support unsized types!", V); + } + if (Attrs.hasAttribute(Attribute::ByRef)) { + Assert(Attrs.getByValType()->isSized(), + "Attributes 'byref' does not support unsized types!", V); + } + if (Attrs.hasAttribute(Attribute::InAlloca)) { + Assert(Attrs.getByValType()->isSized(), + "Attributes 'inalloca' does not support unsized types!", V); + } + if (Attrs.hasAttribute(Attribute::Preallocated)) { + Assert(Attrs.getByValType()->isSized(), + "Attributes 'preallocated' does not support unsized types!", V); + } + } else { + SmallPtrSet Visited; + if (!PTy->getElementType()->isSized(&Visited)) { + Assert(!Attrs.hasAttribute(Attribute::ByVal) && + !Attrs.hasAttribute(Attribute::ByRef) && + !Attrs.hasAttribute(Attribute::InAlloca) && + !Attrs.hasAttribute(Attribute::Preallocated), + "Attributes 'byval', 'byref', 'inalloca', and 'preallocated' do " + "not support unsized types!", + V); + } + if (!isa(PTy->getElementType())) + Assert(!Attrs.hasAttribute(Attribute::SwiftError), + "Attribute 'swifterror' only applies to parameters " + "with pointer to pointer type!", + V); + + if (Attrs.hasAttribute(Attribute::ByRef)) { + 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::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); - } + if (Attrs.hasAttribute(Attribute::Preallocated)) { + Assert(Attrs.getPreallocatedType() == PTy->getElementType(), + "Attribute 'preallocated' type does not match parameter!", V); + } - if (Attrs.hasAttribute(Attribute::InAlloca)) { - Assert(Attrs.getInAllocaType() == PTy->getElementType(), - "Attribute 'inalloca' type does not match parameter!", V); + if (Attrs.hasAttribute(Attribute::InAlloca)) { + Assert(Attrs.getInAllocaType() == PTy->getElementType(), + "Attribute 'inalloca' type does not match parameter!", V); + } } } else { Assert(!Attrs.hasAttribute(Attribute::ByVal),