mboehme created this revision. Herald added subscribers: martong, xazax.hun. Herald added a reviewer: NoQ. Herald added a project: All. mboehme requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This fixes a false positive in the Crubit nullability verification. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152683 Files: clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -5327,4 +5327,37 @@ }); } +// Check that the pointer that a builtin function decays to is associated with +// a value. +TEST(TransferTest, BuiltinFunctionModeled) { + std::string Code = R"( + void target() { + __builtin_expect(0, 0); + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + using ast_matchers::selectFirst; + using ast_matchers::match; + using ast_matchers::traverse; + using ast_matchers::implicitCastExpr; + using ast_matchers::hasCastKind; + + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + auto *ImplicitCast = selectFirst<ImplicitCastExpr>( + "implicit_cast", + match(traverse(TK_AsIs, + implicitCastExpr(hasCastKind(CK_BuiltinFnToFnPtr)) + .bind("implicit_cast")), + ASTCtx)); + + ASSERT_THAT(ImplicitCast, NotNull()); + EXPECT_THAT(Env.getValueStrict(*ImplicitCast), NotNull()); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -400,7 +400,8 @@ Env.setValue(Loc, NullPointerVal); break; } - case CK_FunctionToPointerDecay: { + case CK_FunctionToPointerDecay: + case CK_BuiltinFnToFnPtr: { StorageLocation *PointeeLoc = Env.getStorageLocation(*SubExpr, SkipPast::Reference); if (PointeeLoc == nullptr)
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -5327,4 +5327,37 @@ }); } +// Check that the pointer that a builtin function decays to is associated with +// a value. +TEST(TransferTest, BuiltinFunctionModeled) { + std::string Code = R"( + void target() { + __builtin_expect(0, 0); + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + using ast_matchers::selectFirst; + using ast_matchers::match; + using ast_matchers::traverse; + using ast_matchers::implicitCastExpr; + using ast_matchers::hasCastKind; + + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + auto *ImplicitCast = selectFirst<ImplicitCastExpr>( + "implicit_cast", + match(traverse(TK_AsIs, + implicitCastExpr(hasCastKind(CK_BuiltinFnToFnPtr)) + .bind("implicit_cast")), + ASTCtx)); + + ASSERT_THAT(ImplicitCast, NotNull()); + EXPECT_THAT(Env.getValueStrict(*ImplicitCast), NotNull()); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -400,7 +400,8 @@ Env.setValue(Loc, NullPointerVal); break; } - case CK_FunctionToPointerDecay: { + case CK_FunctionToPointerDecay: + case CK_BuiltinFnToFnPtr: { StorageLocation *PointeeLoc = Env.getStorageLocation(*SubExpr, SkipPast::Reference); if (PointeeLoc == nullptr)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits