From c83044d9bb6a1fc7b0962f499c03144c6858a7bc Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 12 Sep 2016 16:04:59 +0000 Subject: [PATCH] [FunctionAttrs] Don't try to infer returned if it is already on an argument 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. llvm-svn: 281221 --- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 5 +++++ llvm/test/Transforms/FunctionAttrs/returned.ll | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 96dcf9d..0fde107 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -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) diff --git a/llvm/test/Transforms/FunctionAttrs/returned.ll b/llvm/test/Transforms/FunctionAttrs/returned.ll index 4e41969..ede9481 100644 --- a/llvm/test/Transforms/FunctionAttrs/returned.ll +++ b/llvm/test/Transforms/FunctionAttrs/returned.ll @@ -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 +} -- 2.7.4