[clang] 8153773 - [clang][Interp] Fix returning primitive non-blockpointers

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 00:10:01 PDT 2024


Author: Timm Bäder
Date: 2024-06-25T09:09:49+02:00
New Revision: 8153773b23032177546944ec2524dce131b8a46e

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

LOG: [clang][Interp] Fix returning primitive non-blockpointers

We can't deref() them, so return false here.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Pointer.cpp
    clang/test/AST/Interp/literals.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index d77cd8943c496..4070d0c54225d 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -347,7 +347,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx) const {
       Ty = AT->getValueType();
 
     // Invalid pointers.
-    if (Ptr.isDummy() || !Ptr.isLive() ||
+    if (Ptr.isDummy() || !Ptr.isLive() || !Ptr.isBlockPointer() ||
         (!Ptr.isUnknownSizeArray() && Ptr.isOnePastEnd()))
       return false;
 

diff  --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 5a29013a053a2..ef98b4947e64f 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -45,6 +45,8 @@ constexpr int Failed2 = Failed1 + 1; // both-error {{must be initialized by a co
 static_assert(Failed2 == 0, ""); // both-error {{not an integral constant expression}} \
                                  // both-note {{initializer of 'Failed2' is not a constant expression}}
 
+const int x = *(volatile int*)0x1234;
+
 namespace ScalarTypes {
   constexpr int ScalarInitInt = int();
   static_assert(ScalarInitInt == 0, "");


        


More information about the cfe-commits mailing list