public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
@ 2013-10-22 13:14 ` steven.spark+dev at gmail dot com
  2013-10-23  8:24 ` manu at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: steven.spark+dev at gmail dot com @ 2013-10-22 13:14 UTC (permalink / raw)
  To: gcc-bugs

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

Szikra István <steven.spark+dev at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steven.spark+dev at gmail dot com

--- Comment #1 from Szikra István <steven.spark+dev at gmail dot com> ---
I have the same (or similar) problem, and would like to have an option to
enable warnings for incomplete structure initialization with designated
initializers, where not all fields were explicitly assigned. 

(I know that the omitted fields are going to be 0, but that does not help me
much in my embedded project. I would really like a compilation warning for the
occasional misses, and not have to use other code analysis tools. Unfortunately
splint does not even work for gnu99 code.)

More details, examples can be found here:
http://stackoverflow.com/questions/19430285/how-to-ensure-structures-are-completly-initialized-by-name-in-gcc

Thanks in advance for anyone who can help us out.
>From gcc-bugs-return-432466-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Oct 22 13:23:38 2013
Return-Path: <gcc-bugs-return-432466-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 3838 invoked by alias); 22 Oct 2013 13:23:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 3808 invoked by uid 48); 22 Oct 2013 13:23:34 -0000
From: "reichelt at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58846] New: [4.7/4.8/4.9 Regression] ICE redeclaring __dso_handle
Date: Tue, 22 Oct 2013 13:23:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: reichelt at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-58846-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-10/txt/msg01610.txt.bz2
Content-length: 1754

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX846

            Bug ID: 58846
           Summary: [4.7/4.8/4.9 Regression] ICE redeclaring __dso_handle
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: reichelt at gcc dot gnu.org

The following invalid code snippet triggers an ICE since GCC 4.7.0:

=======================================extern "C" { char* __dso_handle; }

struct A
{
  ~A();
};

A a;
=======================================
bug.cc:8:3: error: conflicting declaration 'void* __dso_handle'
 A a;
   ^
bug.cc:1:20: note: '__dso_handle' has a previous declaration as 'char*
__dso_handle'
 extern "C" { char* __dso_handle; }
                    ^
bug.cc: In function 'void __static_initialization_and_destruction_0(int, int)':
bug.cc:8:3: internal compiler error: tree check: expected tree that contains
'decl with visibility' structure, have 'error_mark' in get_dso_handle_node, at
cp/decl.c:6687
 A a;
   ^
0xd17204 tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/gcc/tree.c:9473
0x577e2c contains_struct_check
        ../../gcc/gcc/tree.h:2788
0x577e2c get_dso_handle_node
        ../../gcc/gcc/cp/decl.c:6687
0x577e2c register_dtor_fn(tree_node*)
        ../../gcc/gcc/cp/decl.c:6856
0x6233c7 one_static_initialization_or_destruction
        ../../gcc/gcc/cp/decl2.c:3502
0x623779 do_static_initialization_or_destruction
        ../../gcc/gcc/cp/decl2.c:3579
0x624fa2 cp_write_global_declarations()
        ../../gcc/gcc/cp/decl2.c:4214
Please submit a full bug report, [etc.]


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

* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
  2013-10-22 13:14 ` [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ? steven.spark+dev at gmail dot com
@ 2013-10-23  8:24 ` manu at gcc dot gnu.org
  2014-10-08 12:22 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2013-10-23  8:24 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

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

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Szikra István from comment #1)
> I have the same (or similar) problem, and would like to have an option to
> enable warnings for incomplete structure initialization with designated
> initializers, where not all fields were explicitly assigned. 

I don't think GCC devs would be against this in principle if someone provided a
sensible patch: http://gcc.gnu.org/contribute.html

The relevant code is at gcc/c/c-typeck.c: pop_init_level

  /* Warn when some struct elements are implicitly initialized to zero.  */
  if (warn_missing_field_initializers
      && constructor_type
      && TREE_CODE (constructor_type) == RECORD_TYPE
      && constructor_unfilled_fields)
    {
        bool constructor_zeroinit =
         (vec_safe_length (constructor_elements) == 1
          && integer_zerop ((*constructor_elements)[0].value));

        /* Do not warn for flexible array members or zero-length arrays.  */
        while (constructor_unfilled_fields
               && (!DECL_SIZE (constructor_unfilled_fields)
                   || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
          constructor_unfilled_fields = DECL_CHAIN
(constructor_unfilled_fields);

        if (constructor_unfilled_fields
            /* Do not warn if this level of the initializer uses member
               designators; it is likely to be deliberate.  */
            && !constructor_designated
            /* Do not warn about initializing with ` = {0}'.  */
            && !constructor_zeroinit)
          {
            if (warning_at (input_location, OPT_Wmissing_field_initializers,
                            "missing initializer for field %qD of %qT",
                            constructor_unfilled_fields,
                            constructor_type))
              inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
                      "%qD declared here", constructor_unfilled_fields);
          }
    }


Perhaps sinking the !constructor_designated check into the if, and adding an
'else'? Or simply deleting the check and doing:

            if (warning_at (input_location, 
                            !constructor_designated check ?
OPT_Wmissing_field_initializers : OPT_Wmissing_field_initializers_2,

where OPT_Wmissing_field_initializers_2 corresponds to a new option
Wmissing-field-initializers=2 that needs to be added to c.opt (and documented
in doc/invoke.texi).
>From gcc-bugs-return-432523-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Oct 23 08:42:11 2013
Return-Path: <gcc-bugs-return-432523-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 27053 invoked by alias); 23 Oct 2013 08:42:11 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 27010 invoked by uid 48); 23 Oct 2013 08:42:06 -0000
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/58828] Problem compiling gcc 4.8.2 using gcc 4.4.6
Date: Wed, 23 Oct 2013 08:42:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords: build
X-Bugzilla-Severity: normal
X-Bugzilla-Who: rguenth at gcc dot gnu.org
X-Bugzilla-Status: WAITING
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: keywords bug_status cf_reconfirmed_on everconfirmed
Message-ID: <bug-58828-4-yymcIILRcv@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58828-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58828-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-10/txt/msg01667.txt.bz2
Content-length: 1813

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX828

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |build
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2013-10-23
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
gengtype includes double-int.h and builds with -fkeep-inline-functions which
breaks as double-int.h refers to functions in double-int.c which is not linked
in.

My attempt to reproduce this doesn't get me -fkeep-inline-functions though.

There is

# This pulls in tm-pred.h which contains inline functions wrapping up
# predicates from the back-end so those functions must be discarded.
# No big deal since gencondmd.c is a dummy file for non-GCC compilers.
build/gencondmd.o : \
  BUILD_CFLAGS := $(filter-out -fkeep-inline-functions, $(BUILD_CFLAGS))

in Makefile.in which hints that this kind of issue has hit us before.

It also seems that -fkeep-inline-functions was removed from the toplevel with

2009-06-23  Ian Lance Taylor  <iant@google.com>

        * configure.ac: Add --enable-build-with-cxx.  When set, add c++ to
        boot_languages.  Only bootstrap target libraries listed in
        target_libs for some boot language.  Add --with-stage1-ldflags,
        --with-stage1-libs, --with-boot-ldflags, --with-boot-libs.  Remove
        with_host_libstdcxx from ppllibs.  Only add -fkeep-inline-functions
        if not building with C++.

as I can find no reference of it on the 4.8 branch.

So, please check where -fkeep-inline-functions is coming from in your build.


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

* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
  2013-10-22 13:14 ` [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ? steven.spark+dev at gmail dot com
  2013-10-23  8:24 ` manu at gcc dot gnu.org
@ 2014-10-08 12:22 ` manu at gcc dot gnu.org
  2023-06-09 14:23 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2014-10-08 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Also, I would propose to call the warning -Wmissing-designated-initializers
better than a number that does not mean much.
>From gcc-bugs-return-463552-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Oct 08 12:25:22 2014
Return-Path: <gcc-bugs-return-463552-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 6721 invoked by alias); 8 Oct 2014 12:25:22 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 6680 invoked by uid 55); 8 Oct 2014 12:25:17 -0000
From: "dave.anglin at bell dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ipa/63403] [5.0 Regression] ICE: in relative_time_benefit at ipa-inline.c:869
Date: Wed, 08 Oct 2014 12:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: ipa
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: dave.anglin at bell dot net
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-63403-4-3Oxr30GJcX@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63403-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63403-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-10/txt/msg00573.txt.bz2
Content-length: 515

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc403

--- Comment #5 from dave.anglin at bell dot net ---
Hi Richard,

On 7-Oct-14, at 2:48 PM, rsandifo at gcc dot gnu.org wrote:

> Can you try the patches I posted here:
>
> https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02636.html
> https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02637.html

The patches fix the ICE and restore bootstrap on hppa-unknown-linux-
gnu.  c and c++
tests are running.

Thanks very much,
Dave
--
John David Anglin    dave.anglin@bell.net


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

* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-10-08 12:22 ` manu at gcc dot gnu.org
@ 2023-06-09 14:23 ` cvs-commit at gcc dot gnu.org
  2023-08-24 13:57 ` mail at pfrost dot me
  2023-08-24 16:35 ` manu at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-09 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:0f8f1dee851c23bce19977b2531cf69b4da9f88f

commit r14-1657-g0f8f1dee851c23bce19977b2531cf69b4da9f88f
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Jun 8 13:52:11 2023 -0400

    doc: Clarification for -Wmissing-field-initializers

    The manual is incorrect in saying that the option does not warn
    about designated initializers, which it does in C++.  Whether the
    divergence in behavior is desirable is another thing, but let's
    at least make the manual match the reality.

            PR c/39589
            PR c++/96868

    gcc/ChangeLog:

            * doc/invoke.texi: Clarify that -Wmissing-field-initializers
doesn't
            warn about designated initializers in C only.

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

* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-06-09 14:23 ` cvs-commit at gcc dot gnu.org
@ 2023-08-24 13:57 ` mail at pfrost dot me
  2023-08-24 16:35 ` manu at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: mail at pfrost dot me @ 2023-08-24 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Frost <mail at pfrost dot me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mail at pfrost dot me

--- Comment #14 from Peter Frost <mail at pfrost dot me> ---
Created attachment 55786
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55786&action=edit
Proposed patch

I had a quick go at implementing this as I also wanted this warning. This
implements a `-Wmissing-field-initializers=2` warning for uninitialized
designated initializers

FYI, this is the first time I've worked on the GCC codebase, so I have no idea
if this follow best practices etc. But it seems to work if anyone wanted to try
it out

Thanks,
Peter

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

* [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ?
       [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-08-24 13:57 ` mail at pfrost dot me
@ 2023-08-24 16:35 ` manu at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2023-08-24 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #15 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Peter Frost from comment #14)
> FYI, this is the first time I've worked on the GCC codebase, so I have no
> idea if this follow best practices etc. But it seems to work if anyone
> wanted to try it out

In a nutshell:

1. You need to add some tests that show everything works as expected.
2. You need to run the testsuite
3. You need to submit the patch to gcc-patches.

More details:
https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps

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

end of thread, other threads:[~2023-08-24 16:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-39589-4@http.gcc.gnu.org/bugzilla/>
2013-10-22 13:14 ` [Bug c/39589] make -Wmissing-field-initializers=2 work with "designated initializers" ? steven.spark+dev at gmail dot com
2013-10-23  8:24 ` manu at gcc dot gnu.org
2014-10-08 12:22 ` manu at gcc dot gnu.org
2023-06-09 14:23 ` cvs-commit at gcc dot gnu.org
2023-08-24 13:57 ` mail at pfrost dot me
2023-08-24 16:35 ` manu 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).