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

            Bug ID: 58275
           Summary: __builtin_constant_p( expr ) returns true if expr is
                    eliminated by CSE
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tijl at coosemans dot org

It appears that whenever the expression in __builtin_constant_p( expression )
can be eliminated __builtin_constant_p returns true even if expression is not a
compile-time constant.

Here is an example program. When compiled with -O it returns 1 instead of 2:

int main( int argc, char **argv ) {
    return( argc == 23 ? 0 : __builtin_constant_p( argc != 23 ) ? 1 : 2 );
}

% gcc49 -o test test.c -O
% ./test ; echo $?
1

If you change the first 23 into 24 the program returns 2.

(gcc49 (FreeBSD Ports Collection) 4.9.0 20130818 (experimental))

Reply via email to