[PATCH] D154479: [clang][dataflow] Bug fix: `BuiltinFnToFnPtr` cast does not produce a pointer.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 5 00:47:51 PDT 2023
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.
See comments in the code for details.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154479
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
@@ -5449,8 +5449,8 @@
});
}
-// Check that the pointer that a builtin function decays to is associated with
-// a value.
+// Check that a builtin function is not associated with a value. (It's only
+// possible to call builtin functions directly, not take their address.)
TEST(TransferTest, BuiltinFunctionModeled) {
std::string Code = R"(
void target() {
@@ -5478,7 +5478,7 @@
ASTCtx));
ASSERT_THAT(ImplicitCast, NotNull());
- EXPECT_THAT(Env.getValueStrict(*ImplicitCast), NotNull());
+ EXPECT_THAT(Env.getValueStrict(*ImplicitCast), IsNull());
});
}
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -419,8 +419,7 @@
// FIXME: Implement pointers to members. For now, don't associate a value
// with this expression.
break;
- case CK_FunctionToPointerDecay:
- case CK_BuiltinFnToFnPtr: {
+ case CK_FunctionToPointerDecay: {
StorageLocation *PointeeLoc =
Env.getStorageLocation(*SubExpr, SkipPast::Reference);
if (PointeeLoc == nullptr)
@@ -432,6 +431,12 @@
Env.setValue(PointerLoc, PointerVal);
break;
}
+ case CK_BuiltinFnToFnPtr:
+ // Despite its name, the result type of `BuiltinFnToFnPtr` is a function,
+ // not a function pointer. In addition, builtin functions can only be
+ // called directly; it is not legal to take their address. We therefore
+ // don't need to create a value or storage location for them.
+ break;
default:
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154479.537243.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/02c6ca31/attachment-0001.bin>
More information about the cfe-commits
mailing list