tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  Our Zero opcode only exists for integer types. Use
  visitZeroInitializer() here as well so it works for floats and pointers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149059

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


Index: clang/test/AST/Interp/arrays.cpp
===================================================================
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -334,3 +334,19 @@
                                    // ref-error {{not an integral constant 
expression}} \
                                   // ref-note {{in call to}}
 };
+
+namespace ZeroInit {
+  struct A {
+    int *p[2];
+  };
+  constexpr A a = {};
+  static_assert(a.p[0] == nullptr, "");
+  static_assert(a.p[1] == nullptr, "");
+
+  struct B {
+    double f[2];
+  };
+  constexpr B b = {};
+  static_assert(b.f[0] == 0.0, "");
+  static_assert(b.f[1] == 0.0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1432,7 +1432,7 @@
       //   since we memset our Block*s to 0 and so we have the desired value
       //   without this.
       for (size_t I = 0; I != NumElems; ++I) {
-        if (!this->emitZero(*ElemT, Initializer))
+        if (!this->visitZeroInitializer(CAT->getElementType(), Initializer))
           return false;
         if (!this->emitInitElem(*ElemT, I, Initializer))
           return false;


Index: clang/test/AST/Interp/arrays.cpp
===================================================================
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -334,3 +334,19 @@
                                    // ref-error {{not an integral constant expression}} \
                                   // ref-note {{in call to}}
 };
+
+namespace ZeroInit {
+  struct A {
+    int *p[2];
+  };
+  constexpr A a = {};
+  static_assert(a.p[0] == nullptr, "");
+  static_assert(a.p[1] == nullptr, "");
+
+  struct B {
+    double f[2];
+  };
+  constexpr B b = {};
+  static_assert(b.f[0] == 0.0, "");
+  static_assert(b.f[1] == 0.0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1432,7 +1432,7 @@
       //   since we memset our Block*s to 0 and so we have the desired value
       //   without this.
       for (size_t I = 0; I != NumElems; ++I) {
-        if (!this->emitZero(*ElemT, Initializer))
+        if (!this->visitZeroInitializer(CAT->getElementType(), Initializer))
           return false;
         if (!this->emitInitElem(*ElemT, I, Initializer))
           return false;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to