[clang] [NFC][Clang][UnsafeBufferUsage] Simplify libc function matchers. (PR #178985)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 30 15:02:52 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-analysis
Author: Rohan Jacob-Rao (rohanjr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/178985.diff
1 Files Affected:
- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+3-14)
``````````diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 761aedda7eacf..761cdccc65d50 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1194,9 +1194,7 @@ static bool isUnsafeVaListPrintfFunc(const FunctionDecl &Node) {
StringRef Name = LibcFunNamePrefixSuffixParser().matchName(
II->getName(), Node.getBuiltinID());
- if (!Name.ends_with("printf"))
- return false; // neither printf nor scanf
- return Name.starts_with("v");
+ return Name.starts_with("v") && Name.ends_with("printf");
}
// Matches a call to one of the `sprintf` functions as they are always unsafe
@@ -1210,16 +1208,7 @@ static bool isUnsafeSprintfFunc(const FunctionDecl &Node) {
StringRef Name = LibcFunNamePrefixSuffixParser().matchName(
II->getName(), Node.getBuiltinID());
- if (!Name.ends_with("printf") ||
- // Let `isUnsafeVaListPrintfFunc` check for cases with va-list:
- Name.starts_with("v"))
- return false;
-
- StringRef Prefix = Name.drop_back(6);
-
- if (Prefix.ends_with("w"))
- Prefix = Prefix.drop_back(1);
- return Prefix == "s";
+ return Name == "sprintf" || Name == "swprintf";
}
// Match function declarations of `printf`, `fprintf`, `snprintf` and their wide
@@ -1234,7 +1223,7 @@ static bool isNormalPrintfFunc(const FunctionDecl &Node) {
StringRef Name = LibcFunNamePrefixSuffixParser().matchName(
II->getName(), Node.getBuiltinID());
- if (!Name.ends_with("printf") || Name.starts_with("v"))
+ if (!Name.ends_with("printf"))
return false;
StringRef Prefix = Name.drop_back(6);
``````````
</details>
https://github.com/llvm/llvm-project/pull/178985
More information about the cfe-commits
mailing list