public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
@ 2014-01-17  8:37 josh at joshtriplett dot org
  2014-01-20 20:43 ` [Bug c/59855] " tromey at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-17  8:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

            Bug ID: 59855
           Summary: Support sparse-style __attribute__((designated_init))
                    on structures, requiring designated initializers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josh at joshtriplett dot org

Created attachment 31865
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31865&action=edit
Sparse test case for __attribute__((designated_init))

The Sparse static analyzer provides an extension to force designated
initialization of a structure, __attribute__((designated_init)).  Given a
structure declared with this attribute, Sparse warns if any instance of that
structure gets initialized using a positional initializer, rather than a
designated initializer.  This is useful for structure types likely to change
layout or gain additional fields in the future, to make initializers of the
structure more resilient.

It would help greatly if GCC could support this attribute as well, to make the
warnings more generally available and visible to developers who aren't using
sparse at compilation time.

I've attached Sparse's test case for designated_init, which provides
comprehensive coverage of cases that should and shouldn't generate warnings.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
@ 2014-01-20 20:43 ` tromey at gcc dot gnu.org
  2014-01-20 23:01 ` josh at joshtriplett dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at gcc dot gnu.org @ 2014-01-20 20:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

Tom Tromey <tromey at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at gcc dot gnu.org

--- Comment #1 from Tom Tromey <tromey at gcc dot gnu.org> ---
Patch here: http://gcc.gnu.org/ml/gcc-patches/2014-01/msg01284.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
  2014-01-20 20:43 ` [Bug c/59855] " tromey at gcc dot gnu.org
@ 2014-01-20 23:01 ` josh at joshtriplett dot org
  2014-07-30 15:04 ` tromey at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-20 23:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

--- Comment #2 from Josh Triplett <josh at joshtriplett dot org> ---
Very nice!  Looks reasonable to me.

I agree with making designated_init on a non-struct an error.  Sparse tends to
almost never mark anything as an error unless it mangles Sparse's internal
state somehow, because errors will suppress subsequent warnings (to avoid
cascading issues).  GCC should make it an error.

In theory, designated_init could be meaningful on a union or array; for the
union it would warn on the un-designated initialization of the first member of
the union, and for an array it could require numeric designation.  However, the
latter case seems highly unlikely, and for the former there probably ought to
be a general warning -Wpositional-union-init.  I'd suggest going with this
patch.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
  2014-01-20 20:43 ` [Bug c/59855] " tromey at gcc dot gnu.org
  2014-01-20 23:01 ` josh at joshtriplett dot org
@ 2014-07-30 15:04 ` tromey at gcc dot gnu.org
  2014-07-30 15:06 ` tromey at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at gcc dot gnu.org @ 2014-07-30 15:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

--- Comment #3 from Tom Tromey <tromey at gcc dot gnu.org> ---
Author: tromey
Date: Wed Jul 30 15:02:59 2014
New Revision: 213293

URL: https://gcc.gnu.org/viewcvs?rev=213293&root=gcc&view=rev
Log:
2014-07-30  Tom Tromey  <tromey@redhat.com>

    PR c/59855
    * doc/invoke.texi (Warning Options): Document -Wdesignated-init.
    * doc/extend.texi (Type Attributes): Document designated_init
    attribute.

2014-07-30  Tom Tromey  <tromey@redhat.com>

    PR c/59855
    * c.opt (Wdesignated-init): New option.
    * c-common.c (c_common_attribute_table): Add "designated_init".
    (handle_designated_init): New function.

2014-07-30  Tom Tromey  <tromey@redhat.com>

    * c-typeck.c (struct constructor_stack) <designator_depth>: New
    field.
    (really_start_incremental_init, push_init_level): Initialize
    designator_depth.
    (pop_init_level): Set global designator_depth.
    (process_init_element): Check for designated_init attribute.

Added:
    trunk/gcc/testsuite/gcc.dg/Wdesignated-init.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/c-family/c.opt
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/doc/extend.texi
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
                   ` (2 preceding siblings ...)
  2014-07-30 15:04 ` tromey at gcc dot gnu.org
@ 2014-07-30 15:06 ` tromey at gcc dot gnu.org
  2014-07-31 18:08 ` josh at joshtriplett dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at gcc dot gnu.org @ 2014-07-30 15:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

Tom Tromey <tromey at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.10.0

--- Comment #4 from Tom Tromey <tromey at gcc dot gnu.org> ---
Implemented on trunk.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
                   ` (3 preceding siblings ...)
  2014-07-30 15:06 ` tromey at gcc dot gnu.org
@ 2014-07-31 18:08 ` josh at joshtriplett dot org
  2014-07-31 18:12 ` mpolacek at gcc dot gnu.org
  2014-08-02  5:53 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: josh at joshtriplett dot org @ 2014-07-31 18:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

--- Comment #5 from Josh Triplett <josh at joshtriplett dot org> ---
(In reply to Tom Tromey from comment #4)
> Implemented on trunk.

Thanks!

Please consider including anonymous structs and unions in the test case as
well:

struct S {
    int a;
    union {
        int b;
        int c;
    };
} __attribute__((designated_init));

static struct S s = {
    .a = 0,
    .b = 0,
};

union U {
    int a;
    struct {
        int b;
        int c;
    }  __attribute__((designated_init));
};

static union U u = {
    .b = 0,
    .c = 0,
};

Both of the cases above should produce no warnings; analogous positional
initializers should produce warnings.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
                   ` (4 preceding siblings ...)
  2014-07-31 18:08 ` josh at joshtriplett dot org
@ 2014-07-31 18:12 ` mpolacek at gcc dot gnu.org
  2014-08-02  5:53 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-07-31 18:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Tom: I can add the testcase(s) above if you want.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/59855] Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers
  2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
                   ` (5 preceding siblings ...)
  2014-07-31 18:12 ` mpolacek at gcc dot gnu.org
@ 2014-08-02  5:53 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-08-02  5:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59855

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Sat Aug  2 05:52:30 2014
New Revision: 213515

URL: https://gcc.gnu.org/viewcvs?rev=213515&root=gcc&view=rev
Log:
    PR c/59855
    * gcc.dg/Wdesignated-init-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/Wdesignated-init-2.c
Modified:
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-08-02  5:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17  8:37 [Bug c/59855] New: Support sparse-style __attribute__((designated_init)) on structures, requiring designated initializers josh at joshtriplett dot org
2014-01-20 20:43 ` [Bug c/59855] " tromey at gcc dot gnu.org
2014-01-20 23:01 ` josh at joshtriplett dot org
2014-07-30 15:04 ` tromey at gcc dot gnu.org
2014-07-30 15:06 ` tromey at gcc dot gnu.org
2014-07-31 18:08 ` josh at joshtriplett dot org
2014-07-31 18:12 ` mpolacek at gcc dot gnu.org
2014-08-02  5:53 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).