[PATCH] D31591: Fix a bug which access nullptr and cause segmentation fault

Rui Ueyama via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 12 20:43:54 PDT 2017


It seems to me the test have already been simplified enough, so I'm not
quite sure what you are trying to do more than this. Isn't this just ready
to submit?

On Wed, Apr 12, 2017 at 5:46 PM, Yuka Takahashi via Phabricator <
reviews at reviews.llvm.org> wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170412/dd61dbc7/attachment.html>


More information about the cfe-commits mailing list