This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/52635] New: gcc fails to diagnose invalid type in unused sizeof() when optimizing
- From: "mikpe at it dot uu.se" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 20 Mar 2012 13:16:10 +0000
- Subject: [Bug c/52635] New: gcc fails to diagnose invalid type in unused sizeof() when optimizing
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52635
Bug #: 52635
Summary: gcc fails to diagnose invalid type in unused sizeof()
when optimizing
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mikpe@it.uu.se
Created attachment 26930
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26930
test case
> cat bug.c
extern int bar;
void foo(void)
{
(void)sizeof(char[1 - 2 * !__builtin_constant_p(bar)]);
}
> objdir/gcc/xgcc -Bobjdir/gcc -O1 -S bug.c
> objdir/gcc/xgcc -Bobjdir/gcc -O0 -S bug.c
bug.c: In function 'foo':
bug.c:4:5: error: size of unnamed array is negative
The test case deliberately contains an invalid type expression, but gcc only
diagnoses it at -O0, at -O1 and above there is no error or warning.
Reproduced on x86_64-linux with gcc 4.8-20120318, 4.7.0-RC-20120314, every
4.x.latest release, 3.3.6, and 3.2.3. gcc-3.4.6 fails to diagnose also at -O0.
The test case is based on the Linux kernel's BUILD_BUG_ON() macro.