[llvm] [TLI][NFC] Always init argument F for TargetLibraryInfoImpl::getLibFunc (PR #215746)
Kito Cheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 00:25:20 PDT 2026
https://github.com/kito-cheng created https://github.com/llvm/llvm-project/pull/215746
F may not initialized if the function is not in the list of known functions. This could cause problme if user call that funciton without check return value, and use F as condition check. (and yes, we hit that issue on our downstream code...)
There is two way to improve, first way is this patch, and second is adding `[[nodiscard]]` to force user to check, however use `[[nodiscard]]` will break some existing code, so I choose the first way.
>From c5bce989410bdc0abc8eb5e650279bd2f4ce22d8 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Wed, 12 Aug 2026 00:13:55 -0700
Subject: [PATCH] [TLI] Always init argument F for
TargetLibraryInfoImpl::getLibFunc
F may not initialized if the function is not in the list of known functions.
This could cause problme if user call that funciton without check return value,
and use F as condition check. (and yes, we hit that issue on our downstream
code...)
There is two way to improve, first way is this patch, and second is adding
`[[nodiscard]]` to force user to check, however use `[[nodiscard]]` will break
some existing code, so I choose the first way.
---
llvm/lib/Analysis/TargetLibraryInfo.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 763c04b9b06f7..7dcd4f1a43711 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -973,6 +973,7 @@ buildIndexMap(const llvm::StringTable &StandardNames) {
}
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
+ F = NotLibFunc;
funcName = sanitizeFunctionName(funcName);
if (funcName.empty())
return false;
@@ -1190,6 +1191,7 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
LibFunc &F) const {
+ F = NotLibFunc;
// Intrinsics don't overlap w/libcalls; if our module has a large number of
// intrinsics, this ends up being an interesting compile time win since we
// avoid string normalization and comparison.
@@ -1211,6 +1213,7 @@ bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
bool TargetLibraryInfoImpl::getLibFunc(unsigned int Opcode, Type *Ty,
LibFunc &F) const {
+ F = NotLibFunc;
// Must be a frem instruction with float or double arguments.
if (Opcode != Instruction::FRem || (!Ty->isDoubleTy() && !Ty->isFloatTy()))
return false;
More information about the llvm-commits
mailing list