[clang] ba1d954 - Revert "Revert "Implement nullPointerConstant() using a better API.""
Mikhail Goncharov via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 22 04:44:11 PST 2021
Author: Mikhail Goncharov
Date: 2021-02-22T13:43:42+01:00
New Revision: ba1d9546ee389ce1d2e8f353ae777a65f647d508
URL: https://github.com/llvm/llvm-project/commit/ba1d9546ee389ce1d2e8f353ae777a65f647d508
DIFF: https://github.com/llvm/llvm-project/commit/ba1d9546ee389ce1d2e8f353ae777a65f647d508.diff
LOG: Revert "Revert "Implement nullPointerConstant() using a better API.""
This reverts commit 6984e0d4398592a20055cb12842fc72462ce01a5.
While change by itself seems to be consistent with nullPointerConstant
docs of not matching "int i = 0;" but it's not clear why it's wrong and
9148302a2ae5ac6e5d69ae84042361889247ce64 author just forgot to update
the doc.
Added:
Modified:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index b82929019f6c..6cd4d26768b5 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7384,10 +7384,9 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
/// expr(nullPointerConstant())
/// matches the initializer for v1, v2, v3, cp, and ip. Does not match the
/// initializer for i.
-AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant) {
- return anyOf(
- gnuNullExpr(), cxxNullPtrLiteralExpr(),
- integerLiteral(equals(0), hasParent(expr(hasType(pointerType())))));
+AST_MATCHER(Expr, nullPointerConstant) {
+ return Node.isNullPointerConstant(Finder->getASTContext(),
+ Expr::NPC_ValueDependentIsNull);
}
/// Matches the DecompositionDecl the binding belongs to.
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index c26e8f8d4d22..1c6947acf0ab 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3663,7 +3663,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) {
expr(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_TRUE(matches("int i = 0;", expr(nullPointerConstant())));
}
TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {
More information about the cfe-commits
mailing list