Skip to content

Commit c658ad3

Browse files
committed
Fix non-void return typed non-callee uses
1 parent c43fa0f commit c658ad3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; Make sure we don't break on non-callee uses of funtions with a
2+
; non-void return type.
3+
4+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=values-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
5+
; RUN: FileCheck --check-prefix=RESULT %s < %t
6+
7+
; INTERESTING-LABEL: @interesting(
8+
; INTERESTING: %inttoptr = inttoptr i64
9+
10+
; RESULT-LABEL: define ptr @interesting(i64 %arg) {
11+
; RESULT-NEXT: %inttoptr = inttoptr i64 %arg to ptr
12+
; RESULT-NEXT: ret ptr %inttoptr
13+
define void @interesting(i64 %arg) {
14+
%inttoptr = inttoptr i64 %arg to ptr
15+
%load = load i32, ptr %inttoptr
16+
ret void
17+
}
18+
19+
declare i32 @func(ptr)
20+
21+
; RESULT-LABEL: define i32 @caller() {
22+
; RESULT-NEXT: %call = call i32 @func(ptr @interesting)
23+
; RESULT-NEXT: ret i32 %call
24+
define void @caller() {
25+
%call = call i32 @func(ptr @interesting)
26+
ret void
27+
}

llvm/tools/llvm-reduce/deltas/ReduceValuesToReturn.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ static void rewriteFuncWithReturnType(Function &OldF,
102102
// Adjust the callsite uses to the new return type. We pre-filtered cases
103103
// where the original call type was incorrectly non-void.
104104
for (User *U : make_early_inc_range(OldF.users())) {
105-
if (auto *CB = dyn_cast<CallBase>(U)) {
105+
if (auto *CB = dyn_cast<CallBase>(U);
106+
CB && CB->getCalledOperand() == &OldF) {
106107
if (CB->getType()->isVoidTy()) {
107108
FunctionType *CallType = CB->getFunctionType();
108109

@@ -115,7 +116,7 @@ static void rewriteFuncWithReturnType(Function &OldF,
115116
CB->setCalledFunction(NewCallType, NewF);
116117
} else {
117118
assert(CB->getType() == NewRetTy &&
118-
"only handle exact return type match non-void returns");
119+
"only handle exact return type match with non-void returns");
119120
}
120121
}
121122
}

0 commit comments

Comments
 (0)