[llvm] 237df15 - [Verifier] Check type of swifterror alloca

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 05:53:04 PST 2022


Author: Nikita Popov
Date: 2022-03-11T14:52:56+01:00
New Revision: 237df15c089d4d66ced7c5ba3b91eeda2d9b4fde

URL: https://github.com/llvm/llvm-project/commit/237df15c089d4d66ced7c5ba3b91eeda2d9b4fde
DIFF: https://github.com/llvm/llvm-project/commit/237df15c089d4d66ced7c5ba3b91eeda2d9b4fde.diff

LOG: [Verifier] Check type of swifterror alloca

Per LangRef, swifterror alloca must be a pointer.

Not checking this may result in a verifier error after transforms
instead, so make sure it's discarded early.

Added: 
    

Modified: 
    llvm/lib/IR/Verifier.cpp
    llvm/test/Verifier/swifterror.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 11d27ebfaf9c8..1b3ff1473926f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3875,6 +3875,10 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
   }
 
   if (AI.isSwiftError()) {
+    Assert(AI.getAllocatedType()->isPointerTy(),
+           "swifterror alloca must have pointer type", &AI);
+    Assert(!AI.isArrayAllocation(),
+           "swifterror alloca must not be array allocation", &AI);
     verifySwiftErrorValue(&AI);
   }
 

diff  --git a/llvm/test/Verifier/swifterror.ll b/llvm/test/Verifier/swifterror.ll
index 78c26d7512241..73d79abb1f67d 100644
--- a/llvm/test/Verifier/swifterror.ll
+++ b/llvm/test/Verifier/swifterror.ll
@@ -21,6 +21,18 @@ entry:
   ret float 1.0
 }
 
+; CHECK: swifterror alloca must have pointer type
+define void @swifterror_alloca_invalid_type() {
+  %a = alloca swifterror i128
+  ret void
+}
+
+; CHECK: swifterror alloca must not be array allocation
+define void @swifterror_alloca_array() {
+  %a = alloca swifterror i8*, i64 2
+  ret void
+}
+
 ; CHECK: Cannot have multiple 'swifterror' parameters!
 declare void @a(i32** swifterror %a, i32** swifterror %b)
 


        


More information about the llvm-commits mailing list