Index: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -9111,8 +9111,11 @@ // 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 Index: llvm/trunk/test/CodeGen/X86/arg_returned_bitcast.ll =================================================================== --- llvm/trunk/test/CodeGen/X86/arg_returned_bitcast.ll +++ llvm/trunk/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 +}