From: Johannes Doerfert Date: Tue, 4 Jun 2019 20:34:43 +0000 (+0000) Subject: [SelectionDAG][FIX] Allow "returned" arguments to be bit-casted X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba95ced43406e5c0c05d8314dd029d47845dba53;p=llvm [SelectionDAG][FIX] Allow "returned" arguments to be bit-casted Summary: An argument that is return by a function but bit-casted before can still be annotated as "returned". Make sure we do not crash for this case. Reviewers: sunfish, stephenwlin, niravd, arsenm Subscribers: wdng, hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59917 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362546 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index da06ac7a414..4f7257d4a15 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -9111,8 +9111,11 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const { // for now. if (Args[i].IsReturned && !Op.getValueType().isVector() && CanLowerReturn) { - assert(CLI.RetTy == Args[i].Ty && RetTys.size() == NumValues && - "unexpected use of 'returned'"); + assert((CLI.RetTy == Args[i].Ty || + (CLI.RetTy->isPointerTy() && Args[i].Ty->isPointerTy() && + CLI.RetTy->getPointerAddressSpace() == + Args[i].Ty->getPointerAddressSpace())) && + RetTys.size() == NumValues && "unexpected use of 'returned'"); // Before passing 'returned' to the target lowering code, ensure that // either the register MVT and the actual EVT are the same size or that // the return value and argument are extended in the same way; in these diff --git a/test/CodeGen/X86/arg_returned_bitcast.ll b/test/CodeGen/X86/arg_returned_bitcast.ll new file mode 100644 index 00000000000..2287c129b75 --- /dev/null +++ b/test/CodeGen/X86/arg_returned_bitcast.ll @@ -0,0 +1,12 @@ +; RUN: llc < %s -mtriple=i686-unknown-linux-gnu | FileCheck %s + +; Test that the "returned" attribute "works" even if there is a bitcast between +; the argument and return value. + +declare double* @bar(i8* returned) + +define double* @foo(i8*) { + %r = tail call double* @bar(i8* %0) +; CHECK: jmp bar + ret double* %r +}