r300313 - PR32280: Do not crash on nested initializers.
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 14 01:48:08 PDT 2017
Author: vvassilev
Date: Fri Apr 14 03:48:08 2017
New Revision: 300313
URL: http://llvm.org/viewvc/llvm-project?rev=300313&view=rev
Log:
PR32280: Do not crash on nested initializers.
Patch by Yuka Takahashi (D31591)!
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/designated-initializers.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=300313&r1=300312&r2=300313&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Apr 14 03:48:08 2017
@@ -2270,15 +2270,17 @@ InitListChecker::CheckDesignatedInitiali
assert(StructuredList->getNumInits() == 1
&& "A union should never have more than one initializer!");
- // We're about to throw away an initializer, emit warning.
- SemaRef.Diag(D->getFieldLoc(),
- diag::warn_initializer_overrides)
- << D->getSourceRange();
Expr *ExistingInit = StructuredList->getInit(0);
- SemaRef.Diag(ExistingInit->getLocStart(),
- diag::note_previous_initializer)
- << /*FIXME:has side effects=*/0
- << ExistingInit->getSourceRange();
+ if (ExistingInit) {
+ // We're about to throw away an initializer, emit warning.
+ SemaRef.Diag(D->getFieldLoc(),
+ diag::warn_initializer_overrides)
+ << D->getSourceRange();
+ SemaRef.Diag(ExistingInit->getLocStart(),
+ diag::note_previous_initializer)
+ << /*FIXME:has side effects=*/0
+ << ExistingInit->getSourceRange();
+ }
// remove existing initializer
StructuredList->resizeInits(SemaRef.Context, 0);
Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=300313&r1=300312&r2=300313&view=diff
==============================================================================
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Fri Apr 14 03:48:08 2017
@@ -351,3 +351,20 @@ overwrite_string4[] = {
{ { 'f', 'o', 'o' }, 1 },
[0].L[4] = 'x' // no-warning
};
+
+struct {
+ struct { } s1;
+ union {
+ int a;
+ int b;
+ } u1;
+} s = {
+ .s1 = {
+ .x = 0, // expected-error{{field designator}}
+ },
+
+ .u1 = {
+ .a = 0,
+ .b = 0,
+ },
+};
More information about the cfe-commits
mailing list