File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
lib/Analysis/FlowSensitive
unittests/Analysis/FlowSensitive Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,8 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
400
400
Env.setValue (Loc, NullPointerVal);
401
401
break ;
402
402
}
403
- case CK_FunctionToPointerDecay: {
403
+ case CK_FunctionToPointerDecay:
404
+ case CK_BuiltinFnToFnPtr: {
404
405
StorageLocation *PointeeLoc =
405
406
Env.getStorageLocation (*SubExpr, SkipPast::Reference);
406
407
if (PointeeLoc == nullptr )
Original file line number Diff line number Diff line change @@ -5327,4 +5327,37 @@ TEST(TransferTest, FunctionToPointerDecayHasValue) {
5327
5327
});
5328
5328
}
5329
5329
5330
+ // Check that the pointer that a builtin function decays to is associated with
5331
+ // a value.
5332
+ TEST (TransferTest, BuiltinFunctionModeled) {
5333
+ std::string Code = R"(
5334
+ void target() {
5335
+ __builtin_expect(0, 0);
5336
+ // [[p]]
5337
+ }
5338
+ )" ;
5339
+ runDataflow (
5340
+ Code,
5341
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
5342
+ ASTContext &ASTCtx) {
5343
+ using ast_matchers::selectFirst;
5344
+ using ast_matchers::match;
5345
+ using ast_matchers::traverse;
5346
+ using ast_matchers::implicitCastExpr;
5347
+ using ast_matchers::hasCastKind;
5348
+
5349
+ const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
5350
+
5351
+ auto *ImplicitCast = selectFirst<ImplicitCastExpr>(
5352
+ " implicit_cast" ,
5353
+ match (traverse (TK_AsIs,
5354
+ implicitCastExpr (hasCastKind (CK_BuiltinFnToFnPtr))
5355
+ .bind (" implicit_cast" )),
5356
+ ASTCtx));
5357
+
5358
+ ASSERT_THAT (ImplicitCast, NotNull ());
5359
+ EXPECT_THAT (Env.getValueStrict (*ImplicitCast), NotNull ());
5360
+ });
5361
+ }
5362
+
5330
5363
} // namespace
You can’t perform that action at this time.
0 commit comments