Skip to content

Commit

Permalink
[Attributor] Do not set 'returned' attribute for arguments that canno…
Browse files Browse the repository at this point in the history
…t be bitcasted to function result

Reviewers: jdoerfert, sstefan1, uenoku

Reviewed By: jdoerfert

Subscribers: hiraditya, uenoku, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78828
  • Loading branch information
sndmitriev committed Apr 25, 2020
1 parent f31db76 commit 67aed14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -906,10 +906,13 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {

// If the assumed unique return value is an argument, annotate it.
if (auto *UniqueRVArg = dyn_cast<Argument>(UniqueRV.getValue())) {
// TODO: This should be handled differently!
this->AnchorVal = UniqueRVArg;
this->KindOrArgNo = UniqueRVArg->getArgNo();
Changed = IRAttribute::manifest(A);
if (UniqueRVArg->getType()->canLosslesslyBitCastTo(
getAssociatedFunction()->getReturnType())) {
// TODO: This should be handled differently!
this->AnchorVal = UniqueRVArg;
this->KindOrArgNo = UniqueRVArg->getArgNo();
Changed = IRAttribute::manifest(A);
}
} else if (auto *RVC = dyn_cast<Constant>(UniqueRV.getValue())) {
// We can replace the returned value with the unique returned constant.
Value &AnchorValue = getAnchorValue();
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/Attributor/returned_crash.ll
@@ -0,0 +1,9 @@
; RUN: opt -attributor -S %s | FileCheck %s
; RUN: opt -passes=attributor -S %s | FileCheck %s
;
; CHECK: define i32 addrspace(1)* @foo(i32 addrspace(4)* nofree readnone %arg)
define i32 addrspace(1)* @foo(i32 addrspace(4)* %arg) {
entry:
%0 = addrspacecast i32 addrspace(4)* %arg to i32 addrspace(1)*
ret i32 addrspace(1)* %0
}

0 comments on commit 67aed14

Please sign in to comment.