-
Notifications
You must be signed in to change notification settings - Fork 16k
[NFC][Clang][UnsafeBufferUsage] Simplify libc function matchers. #178985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-analysis Author: Rohan Jacob-Rao (rohanjr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/178985.diff 1 Files Affected:
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);
|
|
@fmayer for review |
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) lldb-apilldb-api.lang/c/calling-conventions/TestCCallingConventions.pylldb-api.lang/cpp/thread_local/TestThreadLocal.pyIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The breakage is unrelated, see #179006.
No description provided.