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/49368] New: __builtin_constant_p is unable to determine if a union is constant


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


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