Re: Counter intuitively, asserts hurt gcc static dataflow analysis.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I tried playing with __builtin_constant_p and __builtin_choose_exp but they
have a very different notion of what a compile time constant is. ie. It's
something a literal or something declared const, _not_ something that is
known at compile time.

Even weirder.... The following compiles without warnings, but.....

#include <stdlib.h>#include <stdio.h>#include <assert.h>
static char __rangeCheckVariable;
#define asshurt(exp)                                               \
   do {                                                            \
      char __rangeCheck[2]="a";                                    \
      __rangeCheckVariable =                                       \
         __rangeCheck[(exp) ? 0 : 10];                             \
   } while(0)
void bunc( int i){

   asshurt( i< 4);
   assert( i<4);
   printf( "%d\n",i);}
void func( int i){
   bunc( i);}
int main( int argc __attribute__((unused)), char * argv[]
__attribute__((unused))){
   int i = 10;

   func( i);

   return 0;}

Removed the line assert( i< 4); and you get

gcc  -g3 -ggdb3 -O3 -W -Wall -Wextra -c d.c ;objdump -S d.o
d.c: In function ‘main’:
d.c:11:22: warning: array subscript is above array bounds [-Warray-bounds]
          __rangeCheck[(exp) ? 0 : 10];                             \
                      ^
d.c:17:4: note: in expansion of macro ‘asshurt’
    asshurt( i< 4);
    ^


ps: Sadly the strange things in the email disclaimer are auto added without
my consent.


-- 
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand

-- 
This Communication is Confidential. We only send and receive email on the

basis of the terms set out at www.taitradio.com/email_disclaimer 
<http://www.taitradio.com/email_disclaimer>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux