This revision was automatically updated to reflect the committed changes.
Closed by commit rG2725e2c0323f: [clang][Interp] Fix ImplicitValueInitExprs for 
pointer types (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137235?vs=472545&id=492049#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137235/new/

https://reviews.llvm.org/D137235

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant 
expression}} \
+                       // ref-error {{must be initialized by a constant 
expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a 
constant expression}} \
+                          // ref-error {{must be initialized by a constant 
expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -279,10 +279,15 @@
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
-  if (std::optional<PrimType> T = classify(E))
-    return this->emitZero(*T, E);
+  std::optional<PrimType> T = classify(E);
 
-  return false;
+  if (!T)
+    return false;
+
+  if (E->getType()->isPointerType())
+    return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template <class Emitter>


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \
+                       // ref-error {{must be initialized by a constant expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \
+                          // ref-error {{must be initialized by a constant expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -279,10 +279,15 @@
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
-  if (std::optional<PrimType> T = classify(E))
-    return this->emitZero(*T, E);
+  std::optional<PrimType> T = classify(E);
 
-  return false;
+  if (!T)
+    return false;
+
+  if (E->getType()->isPointerType())
+    return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template <class Emitter>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to