[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
Mon Apr 3 07:56:17 PDT 2017
yamaguchi updated this revision to Diff 93864.
yamaguchi added a comment.
Made unified diff for the testcase and SemaInit.cpp.
https://reviews.llvm.org/D31591
Files:
SemaInit.cpp
sema-segvcheck.c
Index: sema-segvcheck.c
===================================================================
--- sema-segvcheck.c
+++ sema-segvcheck.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only %s; test $? -eq 1
+
+typedef struct {
+ union {
+ unsigned long long house;
+ struct {
+ unsigned cat1;
+ unsigned cat2;
+ };
+ };
+} struct_0;
+
+
+typedef struct {
+ union {
+ struct {
+ union {
+ unsigned cows;
+ struct {
+ unsigned char c:1;
+ };
+ };
+ };
+ };
+
+ union {
+ struct {
+ unsigned bird0;
+ unsigned bird1;
+ };
+ };
+} struct_1;
+
+
+typedef struct {
+ struct_0 s0;
+ struct_1 s1[1];
+} struct_2;
+
+struct_2 s = {
+ .s0 = {
+ .dog = 0x00000000, // expected-error{{field designator}}
+ },
+
+ .s1[0] = {
+ .cows = 0x00005050,
+ .c = 1,
+ },
+};
Index: SemaInit.cpp
===================================================================
--- SemaInit.cpp
+++ SemaInit.cpp
@@ -2260,15 +2260,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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31591.93864.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170403/dce44c51/attachment-0001.bin>
More information about the cfe-commits
mailing list