Skip to content

Commit 9451004

Browse files
authored
[InstCombine][TLI] Fix function prototype of labs (llvm#69077)
`i64 @labs(i32)` is incorrectly recognized as `LibFunc_labs` because type ID `Long` matches both `i32` and `i64`. This PR requires the type of argument to match the return value. Fixes llvm#69059.
1 parent e1bb059 commit 9451004

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ TLI_DEFINE_SIG_INTERNAL(Int, Int)
15701570
/// long int labs(long int j);
15711571
TLI_DEFINE_ENUM_INTERNAL(labs)
15721572
TLI_DEFINE_STRING_INTERNAL("labs")
1573-
TLI_DEFINE_SIG_INTERNAL(Long, Long)
1573+
TLI_DEFINE_SIG_INTERNAL(Long, Same)
15741574

15751575
/// int lchown(const char *path, uid_t owner, gid_t group);
15761576
TLI_DEFINE_ENUM_INTERNAL(lchown)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
define i64 @pr69059() {
5+
; CHECK-LABEL: define i64 @pr69059() {
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[CALL:%.*]] = call i64 @labs(i32 0)
8+
; CHECK-NEXT: ret i64 [[CALL]]
9+
;
10+
entry:
11+
%call = call i64 @labs(i32 0)
12+
ret i64 %call
13+
}
14+
15+
; negative test: not a valid libfunc proto
16+
declare i64 @labs(i32)

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) {
6969
M->getOrInsertFunction(TLI.getName(LF), InvalidFTy).getCallee());
7070
EXPECT_FALSE(isLibFunc(F, LF));
7171
}
72+
73+
// i64 @labs(i32)
74+
{
75+
auto *InvalidLabsFTy = FunctionType::get(Type::getInt64Ty(Context),
76+
{Type::getInt32Ty(Context)},
77+
/*isVarArg=*/false);
78+
auto *F = cast<Function>(
79+
M->getOrInsertFunction("labs", InvalidLabsFTy).getCallee());
80+
EXPECT_FALSE(isLibFunc(F, LibFunc_labs));
81+
}
7282
}
7383

7484
// Check that we do accept know-correct prototypes.

0 commit comments

Comments
 (0)