Implement checking of the tail keyword.
authorDan Gohman <gohman@apple.com>
Wed, 26 May 2010 21:46:36 +0000 (21:46 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 26 May 2010 21:46:36 +0000 (21:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/Lint.cpp
test/Other/lint.ll

index 25d4f9571dab37a2dff46ab5a552708a3005fa38..8b3873362c8c6b9edf2275d78b54a20514b0511b 100644 (file)
@@ -219,7 +219,15 @@ void Lint::visitCallSite(CallSite CS) {
     // TODO: Check sret attribute.
   }
 
-  // TODO: Check the "tail" keyword constraints.
+  if (CS.isCall() && cast<CallInst>(CS.getInstruction())->isTailCall())
+    for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
+         AI != AE; ++AI) {
+      Value *Obj = (*AI)->getUnderlyingObject();
+      Assert1(!isa<AllocaInst>(Obj) && !isa<VAArgInst>(Obj),
+              "Undefined behavior: Call with \"tail\" keyword references "
+              "alloca or va_arg", &I);
+    }
+
 
   if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I))
     switch (II->getIntrinsicID()) {
index d0db5e46c668723c8e6f4a0570617c915fcbb0dd..eb0b7629e432ff69000f2b22d0e5bced841d7e7b 100644 (file)
@@ -77,8 +77,20 @@ define void @not_vararg(i8* %p) nounwind {
   ret void
 }
 
+; CHECK: Undefined behavior: Branch to non-blockaddress
 define void @use_indbr() {
   indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
 block:
   unreachable
 }
+
+; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
+; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
+declare void @tailcallee(i8*)
+define void @use_tail(i8* %valist) {
+  %t = alloca i8
+  tail call void @tailcallee(i8* %t)
+  %s = va_arg i8* %valist, i8*
+  tail call void @tailcallee(i8* %s)
+  ret void
+}