Skip to content

Commit

Permalink
[SelectionDAG][FIX] Allow "returned" arguments to be bit-casted
Browse files Browse the repository at this point in the history
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

llvm-svn: 362546
  • Loading branch information
Johannes Doerfert committed Jun 4, 2019
1 parent 40107ce commit 6b432dc
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/X86/arg_returned_bitcast.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6b432dc

Please sign in to comment.