public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "stilor at att dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65673] New: Compound literal with initializer for zero-sized array drops other initializers Date: Sun, 05 Apr 2015 06:42:00 -0000 [thread overview] Message-ID: <bug-65673-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673 Bug ID: 65673 Summary: Compound literal with initializer for zero-sized array drops other initializers Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stilor at att dot net I am seeing a strange behavior when a compound initializer is used in a structure initialization. A test case: [[[ struct s { int y; unsigned long *x; }; struct s foo = { .y = 25, .x = (unsigned long [SZ]){}, }; ]]] If SZ is defined to non-zero, the expected output is produced: [[[ /tmp$ gcc -S -o- 1.c -Wall -DSZ=1 .file "1.c" .local __compound_literal.0 .comm __compound_literal.0,8,8 .globl foo .data .align 16 .type foo, @object .size foo, 16 foo: .long 25 .zero 4 .quad __compound_literal.0 .ident "GCC: (Ubuntu 4.9.1-16ubuntu6) 4.9.1" .section .note.GNU-stack,"",@progbits ]]] If SZ is zero, the initializer for .y (".y = 25") member is dropped as well: [[[ /tmp$ gcc -S -o- 1.c -Wall -DSZ=0 .file "1.c" .globl foo .bss .align 16 .type foo, @object .size foo, 16 foo: .zero 16 .ident "GCC: (Ubuntu 4.9.1-16ubuntu6) 4.9.1" .section .note.GNU-stack,"",@progbits ]]] Tested with GCC 4.6.3 and 4.9.1, both exhibit the same behavior. With -Wextra, the code rightfully complains that the initializer for .x is missing - but why the .y initializer is dropped even if there is no initializer for .x? In the mailing list, this was some discussion of this issue: [[[ But in this case, the code attempts to create an unnanmed temporary array of zero elements which, IMO, makes no sense. At the same time, I wouldn't expect gcc to simply omit the initialization for foo.x. I suggest to open a gcc bug for it. ]]] I'd add that this was a reduced test case from a bigger aggregate type - which was an array of such structures. When one of the elements became unused and the size of the bitmap (which was the purpose of the compound literal initializer) was set to zero, the whole array lost its initializers - i.e., even other 'struct s' members of the array, not just the member with a zero-sized array compound literal.
next reply other threads:[~2015-04-05 6:42 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-04-05 6:42 stilor at att dot net [this message] 2015-04-17 7:09 ` [Bug c/65673] " mpolacek at gcc dot gnu.org 2015-04-17 13:03 ` mpolacek at gcc dot gnu.org 2022-01-03 20:34 ` [Bug c/65673] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org 2022-01-17 15:19 ` rguenth at gcc dot gnu.org 2022-05-27 9:35 ` [Bug c/65673] [10/11/12/13 " rguenth at gcc dot gnu.org 2022-06-28 10:31 ` jakub at gcc dot gnu.org 2022-12-20 13:00 ` rguenth at gcc dot gnu.org 2023-01-31 1:29 ` luangruo at yahoo dot com 2023-07-07 10:30 ` [Bug c/65673] [11/12/13/14 " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-65673-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).