Skip to content

Commit 7c30897

Browse files
committed
[TLI] Handle cabs without parameters gracefully
Check that the function has at least one parameter before trying to access its type. Fixes #148770.
1 parent a789b3f commit 7c30897

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
11221122
case LibFunc_cabsf:
11231123
case LibFunc_cabsl: {
11241124
Type *RetTy = FTy.getReturnType();
1125-
if (!RetTy->isFloatingPointTy())
1125+
if (!RetTy->isFloatingPointTy() || NumParams == 0)
11261126
return false;
11271127

11281128
Type *ParamTy = FTy.getParamType(0);

llvm/test/Transforms/InferFunctionAttrs/no-proto.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,6 @@ declare void @vsscanf(...)
977977

978978
; CHECK: declare void @write(...)
979979
declare void @write(...)
980+
981+
; CHECK: declare double @cabs(...)
982+
declare double @cabs(...)

0 commit comments

Comments
 (0)