Skip to content

Commit 8d5c8d5

Browse files
committed
[InlineCost] Check that function types match
Retain the behavior we get without opaque pointers: A call to a known function with different function type is considered an indirect call. This fixes the crash reported in https://reviews.llvm.org/D123300#3444772.
1 parent dbd80d7 commit 8d5c8d5

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,14 +2136,14 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) {
21362136
if (isa<CallInst>(Call) && cast<CallInst>(Call).cannotDuplicate())
21372137
ContainsNoDuplicateCall = true;
21382138

2139-
Value *Callee = Call.getCalledOperand();
2140-
Function *F = dyn_cast_or_null<Function>(Callee);
2139+
Function *F = Call.getCalledFunction();
21412140
bool IsIndirectCall = !F;
21422141
if (IsIndirectCall) {
21432142
// Check if this happens to be an indirect function call to a known function
21442143
// in this inline context. If not, we've done all we can.
2144+
Value *Callee = Call.getCalledOperand();
21452145
F = dyn_cast_or_null<Function>(SimplifiedValues.lookup(Callee));
2146-
if (!F) {
2146+
if (!F || F->getFunctionType() != Call.getFunctionType()) {
21472147
onCallArgumentSetup(Call);
21482148

21492149
if (!Call.onlyReadsMemory())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -inline < %s | FileCheck %s
3+
4+
define void @test(ptr %p1, ptr %p2) {
5+
; CHECK-LABEL: @test(
6+
; CHECK-NEXT: ret void
7+
;
8+
ret void
9+
}
10+
11+
define void @test1() {
12+
; CHECK-LABEL: @test1(
13+
; CHECK-NEXT: [[CALL_I:%.*]] = call i32 @test(ptr null)
14+
; CHECK-NEXT: ret void
15+
;
16+
call void @test2(ptr @test)
17+
ret void
18+
}
19+
20+
define void @test2(ptr %i) {
21+
; CHECK-LABEL: @test2(
22+
; CHECK-NEXT: [[CALL:%.*]] = call i32 [[I:%.*]](ptr null)
23+
; CHECK-NEXT: ret void
24+
;
25+
%call = call i32 %i(ptr null)
26+
ret void
27+
}

0 commit comments

Comments
 (0)