[clang] ca01be5 - [clang][dataflow] Bug fix: `BuiltinFnToFnPtr` cast does not produce a pointer.

Martin Braenne via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 23:56:13 PDT 2023


Author: Martin Braenne
Date: 2023-07-06T06:56:02Z
New Revision: ca01be54c1e94c552eceb00fc21b4363fae63d6c

URL: https://github.com/llvm/llvm-project/commit/ca01be54c1e94c552eceb00fc21b4363fae63d6c
DIFF: https://github.com/llvm/llvm-project/commit/ca01be54c1e94c552eceb00fc21b4363fae63d6c.diff

LOG: [clang][dataflow] Bug fix: `BuiltinFnToFnPtr` cast does not produce a pointer.

See comments in the code for details.

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D154479

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/Transfer.cpp
    clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 5ad176dc1cdbe9..d69e0f5a5e1030 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -419,8 +419,7 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
       // 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 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
       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;
     }

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 3f99ff5652ce28..83ea176034c0d7 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5480,8 +5480,8 @@ TEST(TransferTest, FunctionToPointerDecayHasValue) {
       });
 }
 
-// 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() {
@@ -5509,7 +5509,7 @@ TEST(TransferTest, BuiltinFunctionModeled) {
                   ASTCtx));
 
         ASSERT_THAT(ImplicitCast, NotNull());
-        EXPECT_THAT(Env.getValueStrict(*ImplicitCast), NotNull());
+        EXPECT_THAT(Env.getValueStrict(*ImplicitCast), IsNull());
       });
 }
 


        


More information about the cfe-commits mailing list