Env.setValue(Loc, NullPointerVal);
break;
}
- case CK_FunctionToPointerDecay: {
+ case CK_FunctionToPointerDecay:
+ case CK_BuiltinFnToFnPtr: {
StorageLocation *PointeeLoc =
Env.getStorageLocation(*SubExpr, SkipPast::Reference);
if (PointeeLoc == nullptr)
});
}
+// 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