r292245 - [Sema] Fix bug in handling of designated initializer.
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 17 11:35:54 PST 2017
Author: ahatanak
Date: Tue Jan 17 13:35:54 2017
New Revision: 292245
URL: http://llvm.org/viewvc/llvm-project?rev=292245&view=rev
Log:
[Sema] Fix bug in handling of designated initializer.
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.
rdar://problem/26795040
Differential Revision: https://reviews.llvm.org/D28705
Added:
cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=292245&r1=292244&r2=292245&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jan 17 13:35:54 2017
@@ -2237,6 +2237,10 @@ InitListChecker::CheckDesignatedInitiali
}
unsigned FieldIndex = 0;
+
+ if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
+ FieldIndex = CXXRD->getNumBases();
+
for (auto *FI : RT->getDecl()->fields()) {
if (FI->isUnnamedBitfield())
continue;
Added: cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp?rev=292245&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp (added)
+++ cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp Tue Jan 17 13:35:54 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -std=c++1z -fsyntax-only -verify -Winitializer-overrides
+// expected-no-diagnostics
+
+struct B {
+ int x;
+};
+
+struct D : B {
+ int y;
+};
+
+void test() { D d = {1, .y = 2}; }
More information about the cfe-commits
mailing list