[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault
Yuka Takahashi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 12 17:46:17 PDT 2017
yamaguchi updated this revision to Diff 95064.
yamaguchi added a comment.
I've been trying to minimal the testcase, add comments to describe what it is testing, and fix styles of the testcase properly.
However, I don't have clear idea what will be the best. I would like to ask for the advice.
https://reviews.llvm.org/D31591
Files:
lib/Sema/SemaInit.cpp
test/Sema/designated-initializers.c
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -2269,15 +2269,17 @@
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);
Index: test/Sema/designated-initializers.c
===================================================================
--- test/Sema/designated-initializers.c
+++ test/Sema/designated-initializers.c
@@ -351,3 +351,20 @@
{ { '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,
+ },
+};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31591.95064.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170413/45b75aa9/attachment.bin>
More information about the cfe-commits
mailing list