[PATCH] D28705: [Sema] Fix bug in handling of designated initializer

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 14:43:33 PST 2017


ahatanak created this revision.
ahatanak added reviewers: rsmith, rnk, arphaman.
ahatanak added a subscriber: cfe-commits.

CheckDesignatedInitializer wasn't taking into account the base classes when computing the index for the field in the derived class, which caused the test case to crash during IRGen because of a malformed AST.


https://reviews.llvm.org/D28705

Files:
  lib/Sema/SemaInit.cpp
  test/SemaCXX/designated-initializers-base-class.cpp


Index: test/SemaCXX/designated-initializers-base-class.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/designated-initializers-base-class.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -std=c++1z -ast-dump | FileCheck %s
+
+// CHECK: VarDecl {{.*}} d 'struct D' cinit
+// CHECK: InitListExpr {{.*}} 'struct D'
+// CHECK: InitListExpr {{.*}} 'struct B'
+// CHECK: ImplicitValueInitExpr {{.*}} 'int'
+// CHECK: IntegerLiteral {{.*}} 'int' 1
+
+struct B {
+  int x;
+};
+
+struct D : B {
+  int y;
+};
+
+void test() {
+  D d = { .y = 1 };
+}
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2247,6 +2247,9 @@
       ++FieldIndex;
     }
 
+    if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
+      FieldIndex += CXXRD->getNumBases();
+
     RecordDecl::field_iterator Field =
         RecordDecl::field_iterator(DeclContext::decl_iterator(KnownField));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28705.84390.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170113/26ac4e42/attachment.bin>


More information about the cfe-commits mailing list