This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/52635] gcc fails to diagnose invalid type in unused sizeof() when optimizing


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

--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-03-20 15:13:13 UTC ---
On Tue, 20 Mar 2012, mikpe at it dot uu.se wrote:

> > 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.

Do you have an example not involving __builtin_constant_p?  When 
optimizing, this array will be considered a VLA (i.e. the size will be 
considered nonconstant) as __builtin_constant_p is only evaluated later 
(after inlining, for example), long after decisions about whether arrays 
are VLAs have to be made.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]