https://github.com/KHicketts updated https://github.com/llvm/llvm-project/pull/201893
>From f238457992ea5315c63430927c39c1d1c8d494dd Mon Sep 17 00:00:00 2001 From: khickett <[email protected]> Date: Fri, 5 Jun 2026 18:03:02 +0100 Subject: [PATCH] Fix false match on nullPointerConstant for array indices --- clang/include/clang/ASTMatchers/ASTMatchers.h | 2 +- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index bc0f35898a2c9..24d9eea98df9b 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -8369,7 +8369,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant) { return anyOf( gnuNullExpr(), cxxNullPtrLiteralExpr(), - integerLiteral(equals(0), hasParent(expr(hasType(pointerType()))))); + integerLiteral(equals(0), hasParent(castExpr(hasCastKind(CK_NullToPointer))))); } /// Matches the DecompositionDecl the binding belongs to. diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index d9647c201fc30..d51f70b867ac9 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -4049,6 +4049,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) { EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant()))); EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant()))); EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant()))); + EXPECT_FALSE(matches("int *p[1]; (void)p[0];", expr(nullPointerConstant()))); } TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
