This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bug with compound literal initializer?
- From: Alexey Neyman <stilor at att dot net>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 24 Mar 2015 14:26:00 -0700
- Subject: Bug with compound literal initializer?
- Authentication-results: sourceware.org; auth=none
Hi,
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
]]]
Is it expected behavior? If so, why?
Tested with GCC 4.6.3 and 4.9.1, both exhibit the same behavior.
Thanks,
Alexey.