http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60722
Bug ID: 60722 Summary: __builtin_choose_expr() does not allow 'CONST_EXP' using const variable Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: yann at droneaud dot fr Created attachment 32498 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32498&action=edit testcase Hi, I'm trying to use __builtin_choose_expr() with a test against a const variable: #define VALUE 123 int test(void) { const int value = VALUE; int v1, v2; v1 = __builtin_choose_expr(__builtin_constant_p(VALUE), (__builtin_choose_expr(VALUE >= 10, 2, (__builtin_choose_expr(VALUE >= 0, 1, 0)))), -1); v1 = __builtin_choose_expr(__builtin_constant_p(value), (__builtin_choose_expr(value >= 10, 2, (__builtin_choose_expr(value >= 0, 1, 0)))), -1); return v1 - v2; } The first expression is considering a constant defined as a macro. And the second expression is considering a constant variable. With gcc 4.9.0 20140313 (experimental), I'm facing the following error: $ /opt/gcc/bin/gcc -O2 -c test.c test.c: In function ‘test’: test.c:21:11: erreur: first argument to ‘__builtin_choose_expr’ not a constant (__builtin_choose_expr(value >= 0, ^ test.c:19:9: erreur: first argument to ‘__builtin_choose_expr’ not a constant (__builtin_choose_expr(value >= 10, ^ (Note: with gcc 4.8, I'm also having the issue with _builtin_constant_p(value), as bug #19449) It's a pity gcc is not able to consider (value >= 0) as a constant expression while its obvious that 'value' is a constant variable (!). It makes usage of __builtin_choose_expr() not applicable in my case.