https://github.com/rohanjr created 
https://github.com/llvm/llvm-project/pull/178985

None

>From afaf977ff851fcd05fecf574d0c6286d9bed3db5 Mon Sep 17 00:00:00 2001
From: Rohan Jacob-Rao <[email protected]>
Date: Fri, 30 Jan 2026 22:51:56 +0000
Subject: [PATCH] [NFC][Clang][UnsafeBufferUsage] Simplify libc function
 matchers.

---
 clang/lib/Analysis/UnsafeBufferUsage.cpp | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

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);

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to