[llvm] [TLI][NFC] Always init argument F for TargetLibraryInfoImpl::getLibFunc (PR #215746)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 00:26:00 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kito Cheng (kito-cheng)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/215746.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+3) 


``````````diff
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/215746


More information about the llvm-commits mailing list