[PATCH] D152683: [clang][dataflow] Model pointer value for builtin functions.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 12 05:23:42 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3f31d3204bd2: [clang][dataflow] Model pointer value for builtin functions. (authored by mboehme).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152683/new/
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152683.530470.patch
Type: text/x-patch
Size: 1954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230612/b7960d13/attachment-0001.bin>
More information about the cfe-commits
mailing list