This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG056042d21b72: [clang][Interp] Fix initializing fields after 
base class members (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D145860?vs=504408&id=510487#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145860

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


Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@
   constexpr Outer O;
   static_assert(O.bar() == 12);
 }
+
+namespace BaseAndFieldInit {
+  struct A {
+    int a;
+  };
+
+  struct B : A {
+    int b;
+  };
+
+  struct C : B {
+    int c;
+  };
+
+  constexpr C c = {1,2,3};
+  static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@
 
         if (!this->emitPopPtr(Initializer))
           return false;
+        ++InitIndex;
       } else {
         // Initializer for a direct base class.
         if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@
 
           if (!this->emitPopPtr(Initializer))
             return false;
+          // Base initializers don't increase InitIndex, since they don't count
+          // into the Record's fields.
         } else {
           const Record::Field *FieldToInit = R->getField(InitIndex);
           // Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@
 
           if (!this->emitPopPtr(Initializer))
             return false;
+          ++InitIndex;
         }
       }
-      ++InitIndex;
     }
 
     return true;


Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@
   constexpr Outer O;
   static_assert(O.bar() == 12);
 }
+
+namespace BaseAndFieldInit {
+  struct A {
+    int a;
+  };
+
+  struct B : A {
+    int b;
+  };
+
+  struct C : B {
+    int c;
+  };
+
+  constexpr C c = {1,2,3};
+  static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@
 
         if (!this->emitPopPtr(Initializer))
           return false;
+        ++InitIndex;
       } else {
         // Initializer for a direct base class.
         if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@
 
           if (!this->emitPopPtr(Initializer))
             return false;
+          // Base initializers don't increase InitIndex, since they don't count
+          // into the Record's fields.
         } else {
           const Record::Field *FieldToInit = R->getField(InitIndex);
           // Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@
 
           if (!this->emitPopPtr(Initializer))
             return false;
+          ++InitIndex;
         }
       }
-      ++InitIndex;
     }
 
     return true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to