Author: Timm Bäder
Date: 2024-07-16T08:28:51+02:00
New Revision: d8f0611acc2658ccc54d985044aa115716c6ad34

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

LOG: [clang][Interp] Allow ltor casts for null pointers

We can't read from them but we special-case them later.

Added: 
    

Modified: 
    clang/lib/AST/Interp/EvalEmitter.cpp
    clang/test/CodeGenCXX/nullptr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 1a9444d38fdd5..74413baf6fc0c 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -152,7 +152,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const 
SourceInfo &Info) {
 
   // Implicitly convert lvalue to rvalue, if requested.
   if (ConvertResultToRValue) {
-    if (!Ptr.isDereferencable())
+    if (!Ptr.isZero() && !Ptr.isDereferencable())
       return false;
     // Never allow reading from a non-const pointer, unless the memory
     // has been created in this evaluation.

diff  --git a/clang/test/CodeGenCXX/nullptr.cpp 
b/clang/test/CodeGenCXX/nullptr.cpp
index ca76c55e2122d..0d8837b216bec 100644
--- a/clang/test/CodeGenCXX/nullptr.cpp
+++ b/clang/test/CodeGenCXX/nullptr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o 
- %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o 
- %s -fexperimental-new-constant-interpreter | FileCheck %s
 
 #include <typeinfo>
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to