[PATCH] D114559: [clang] ASTMatchers: Fix out-of-bounds access in foreachArgumentWithParamType.
Felix Berger via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 15 09:36:52 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa1b1c23a3b5f: [clang] ASTMatchers: Fix out-of-bounds access in foreachArgumentWithParamType. (authored by flx).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114559/new/
https://reviews.llvm.org/D114559
Files:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1094,6 +1094,31 @@
S, CallExpr, std::make_unique<VerifyIdIsBoundTo<DeclRefExpr>>("arg")));
}
+TEST(ForEachArgumentWithParamType, MatchesVariadicFunctionPtrCalls) {
+ StatementMatcher ArgumentY =
+ declRefExpr(to(varDecl(hasName("y")))).bind("arg");
+ TypeMatcher IntType = qualType(builtinType()).bind("type");
+ StatementMatcher CallExpr =
+ callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+ StringRef S = R"cpp(
+ void fcntl(int fd, int cmd, ...) {}
+
+ template <typename Func>
+ void f(Func F) {
+ int y = 42;
+ F(y, 1, 3);
+ }
+
+ void g() { f(fcntl); }
+ )cpp";
+
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ S, CallExpr, std::make_unique<VerifyIdIsBoundTo<QualType>>("type")));
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ S, CallExpr, std::make_unique<VerifyIdIsBoundTo<DeclRefExpr>>("arg")));
+}
+
TEST(QualType, hasCanonicalType) {
EXPECT_TRUE(notMatches("typedef int &int_ref;"
"int a;"
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4886,7 +4886,7 @@
// This test is cheaper compared to the big matcher in the next if.
// Therefore, please keep this order.
- if (FProto) {
+ if (FProto && FProto->getNumParams() > ParamIndex) {
QualType ParamType = FProto->getParamType(ParamIndex);
if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {
Result.addMatch(ParamMatches);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114559.394588.patch
Type: text/x-patch
Size: 1881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211215/75699f77/attachment.bin>
More information about the cfe-commits
mailing list