[PATCH] IR: Conservatively verify inalloca arguments

David Majnemer david.majnemer at gmail.com
Mon May 19 07:23:34 PDT 2014


Closed by commit rL207676 (authored by @majnemer).

http://reviews.llvm.org/D3572

Files:
  llvm/trunk/lib/IR/Verifier.cpp
  llvm/trunk/test/Transforms/ArgumentPromotion/inalloca.ll
  llvm/trunk/test/Transforms/InstCombine/call-cast-target-inalloca.ll
  llvm/trunk/test/Verifier/inalloca3.ll

Index: llvm/trunk/lib/IR/Verifier.cpp
===================================================================
--- llvm/trunk/lib/IR/Verifier.cpp
+++ llvm/trunk/lib/IR/Verifier.cpp
@@ -1494,6 +1494,16 @@
   // Verify call attributes.
   VerifyFunctionAttrs(FTy, Attrs, I);
 
+  // Conservatively check the inalloca argument.
+  // We have a bug if we can find that there is an underlying alloca without
+  // inalloca.
+  if (CS.hasInAllocaArgument()) {
+    Value *InAllocaArg = CS.getArgument(FTy->getNumParams() - 1);
+    if (auto AI = dyn_cast<AllocaInst>(InAllocaArg->stripInBoundsOffsets()))
+      Assert2(AI->isUsedWithInAlloca(),
+              "inalloca argument for call has mismatched alloca", AI, I);
+  }
+
   if (FTy->isVarArg()) {
     // FIXME? is 'nest' even legal here?
     bool SawNest = false;
Index: llvm/trunk/test/Transforms/InstCombine/call-cast-target-inalloca.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/call-cast-target-inalloca.ll
+++ llvm/trunk/test/Transforms/InstCombine/call-cast-target-inalloca.ll
@@ -8,7 +8,7 @@
 
 define void @f() {
 ; CHECK-LABEL: define void @f()
-  %args = alloca i32
+  %args = alloca inalloca i32
   call void bitcast (void (i32)* @takes_i32 to void (i32*)*)(i32* inalloca %args)
 ; CHECK: call void bitcast
   ret void
Index: llvm/trunk/test/Transforms/ArgumentPromotion/inalloca.ll
===================================================================
--- llvm/trunk/test/Transforms/ArgumentPromotion/inalloca.ll
+++ llvm/trunk/test/Transforms/ArgumentPromotion/inalloca.ll
@@ -20,7 +20,7 @@
 
 define i32 @main() {
 entry:
-  %S = alloca %struct.ss
+  %S = alloca inalloca %struct.ss
   %f0 = getelementptr %struct.ss* %S, i32 0, i32 0
   %f1 = getelementptr %struct.ss* %S, i32 0, i32 1
   store i32 1, i32* %f0, align 4
@@ -42,7 +42,7 @@
 
 define i32 @test() {
 entry:
-  %S = alloca %struct.ss
+  %S = alloca inalloca %struct.ss
   %c = call i1 @g(%struct.ss* %S, %struct.ss* inalloca %S)
 ; CHECK: call i1 @g(%struct.ss* %S, %struct.ss* inalloca %S)
   ret i32 0
Index: llvm/trunk/test/Verifier/inalloca3.ll
===================================================================
--- llvm/trunk/test/Verifier/inalloca3.ll
+++ llvm/trunk/test/Verifier/inalloca3.ll
@@ -0,0 +1,13 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+
+declare void @doit(i64* inalloca %a)
+
+define void @a() {
+entry:
+  %a = alloca [2 x i32]
+  %b = bitcast [2 x i32]* %a to i64*
+  call void @doit(i64* inalloca %b)
+; CHECK: inalloca argument for call has mismatched alloca
+  ret void
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3572.9547.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140519/27a7a74f/attachment.bin>


More information about the llvm-commits mailing list