[PATCH] D101108: [PR49761] Fix variadic arg handling in matcher
Chris Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 23 10:07:31 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcae3b70cebc1: [PR49761] Fix variadic arg handling in matcher (authored by chrish_ericsson_atx).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101108/new/
https://reviews.llvm.org/D101108
Files:
clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
clang/include/clang/ASTMatchers/ASTMatchers.h
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4757,8 +4757,11 @@
int ParamIndex = 0;
bool Matched = false;
+ unsigned NumArgs = Node.getNumArgs();
+ if (FProto && FProto->isVariadic())
+ NumArgs = std::min(NumArgs, FProto->getNumParams());
- for (; ArgIndex < Node.getNumArgs(); ++ArgIndex, ++ParamIndex) {
+ for (; ArgIndex < NumArgs; ++ArgIndex, ++ParamIndex) {
BoundNodesTreeBuilder ArgMatches(*Builder);
if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder,
&ArgMatches)) {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -386,3 +386,18 @@
do {
} while (false && CondVar);
}
+
+struct logger {
+ void (*debug)(struct logger *, const char *, ...);
+};
+
+int foo(void) {
+ struct logger *pl = 0;
+ int iterator = 0;
+ while (iterator < 10) {
+ char *l_tmp_msg = 0;
+ pl->debug(pl, "%d: %s\n", iterator, l_tmp_msg);
+ iterator++;
+ }
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101108.340097.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210423/d58fb56c/attachment.bin>
More information about the cfe-commits
mailing list