[PATCH] D104309: [OpaquePtr] Verify Opaque pointer in function parameter
Zequan Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 15 10:01:39 PDT 2021
zequanwu created this revision.
zequanwu added a reviewer: aeubanks.
Herald added subscribers: dexonsmith, hiraditya.
zequanwu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Verifying opaque pointer as function parameter when using with `byval`, `byref`,
`inalloca`, `preallocated`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104309
Files:
llvm/lib/IR/Verifier.cpp
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1839,40 +1839,59 @@
V);
if (PointerType *PTy = dyn_cast<PointerType>(Ty)) {
- SmallPtrSet<Type*, 4> 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<PointerType>(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<Type *, 4> 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<PointerType>(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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104309.352172.patch
Type: text/x-patch
Size: 4215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210615/0bcd63b6/attachment.bin>
More information about the llvm-commits
mailing list