This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant
- From: "david.meggy at icron dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 10 Jun 2011 18:24:48 +0000
- Subject: [Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49368
Summary: __builtin_constant_p is unable to determine if a union
is constant
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: david.meggy@icron.com
In the following code GCC seems to be unable to determine that a const union is
actually const when passed as an argument to __builtin_constant_p(). If I use
a struct instead, then it seems to work, so there is only an issue when using a
union.
This is tested on GCC 4.5.1 & GCC 4.1.2
$ cat dummy.c
#include <stdio.h>
union u {
int a;
int b;
};
#define DO_WORK(_arg_) \
do { \
if (__builtin_constant_p(_arg_)) \
{ \
printf("Do optimized code\n"); \
} \
else \
{ \
printf("Do slow code\n"); \
} \
} while (0 == 1)
int main()
{
const union u x = { .a = 0 } ;
DO_WORK(x.b);
return 0;
}
$ gcc -Wall -Os dummy.c
$ ./a.out
Do slow code