]> granicus.if.org Git - llvm/commitdiff
[FunctionAttrs] Don't try to infer returned if it is already on an argument
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Sep 2016 16:04:59 +0000 (16:04 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Sep 2016 16:04:59 +0000 (16:04 +0000)
Trying to infer the 'returned' attribute if an argument is already
'returned' can lead to verification failure: inference might determine
that a different argument is passed through which would result in two
different arguments marked as 'returned'.

This fixes PR30350.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281221 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionAttrs.cpp
test/Transforms/FunctionAttrs/returned.ll

index 96dcf9de7d507d6e4849ec8f49ec5341213ef448..0fde10752b56db8d4f7ca59075af2d6149624c9a 100644 (file)
@@ -496,6 +496,11 @@ static bool addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes) {
     if (F->getReturnType()->isVoidTy())
       continue;
 
+    // There is nothing to do if an argument is already marked as 'returned'.
+    if (any_of(F->args(),
+               [](const Argument &Arg) { return Arg.hasReturnedAttr(); }))
+      continue;
+
     auto FindRetArg = [&]() -> Value * {
       Value *RetArg = nullptr;
       for (BasicBlock &BB : *F)
index 4e419693d9f43866c5822d301971452fa9bdeaa3..ede9481e433877825177e8ecb5c7f9aabe17b118 100644 (file)
@@ -16,3 +16,15 @@ lor.lhs.false:                                    ; preds = %entry
 cond.end:                                         ; preds = %entry
   ret i32 %p
 }
+
+; CHECK: define i32 @test2(i32 %p1, i32 returned %p2)
+define i32 @test2(i32 %p1, i32 returned %p2) {
+  %_tmp4 = icmp eq i32 %p1, %p2
+  br i1 %_tmp4, label %bb2, label %bb1
+
+bb2:                                              ; preds = %0
+  ret i32 %p1
+
+bb1:                                              ; preds = %bb1, %0
+  br label %bb1
+}