Author: Timm Bäder
Date: 2024-06-15T11:38:57+02:00
New Revision: 17712f501c63998e67178e817ee64612cd1daae3

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

LOG: [clang][Interp] Fix checking null pointers for initialization

Added: 
    

Modified: 
    clang/lib/AST/Interp/EvaluationResult.cpp
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp 
b/clang/lib/AST/Interp/EvaluationResult.cpp
index 387e3dc88bff2..395e3f5b4348d 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -141,7 +141,9 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
                                              const Pointer &Ptr) const {
   assert(Source);
   assert(empty());
-  assert(!Ptr.isZero());
+
+  if (Ptr.isZero())
+    return true;
 
   SourceLocation InitLoc;
   if (const auto *D = Source.dyn_cast<const Decl *>())

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 434823644a7a3..2faacbbf70fd7 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -814,3 +814,16 @@ namespace GH64949 {
                               // both-note {{subobject 'g' is not 
initialized}} \
                               // both-warning {{expression result unused}}
 }
+
+/// This used to cause an assertion failure inside 
EvaluationResult::checkFullyInitialized.
+namespace CheckingNullPtrForInitialization {
+  struct X {
+    consteval operator const char *() const {
+      return nullptr;
+    }
+  };
+  const char *f() {
+    constexpr X x;
+    return x;
+  }
+}


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

Reply via email to