public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant
@ 2011-06-10 18:25 david.meggy at icron dot com
  2011-06-12 11:38 ` [Bug c/49368] " rguenth at gcc dot gnu.org
  2011-06-13 16:03 ` david.meggy at icron dot com
  0 siblings, 2 replies; 3+ messages in thread
From: david.meggy at icron dot com @ 2011-06-10 18:25 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/49368] __builtin_constant_p is unable to determine if a union is constant
  2011-06-10 18:25 [Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant david.meggy at icron dot com
@ 2011-06-12 11:38 ` rguenth at gcc dot gnu.org
  2011-06-13 16:03 ` david.meggy at icron dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-12 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-12 11:38:26 UTC ---
Works for me with 4.5.3 and 4.6.0, fails with 4.4.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/49368] __builtin_constant_p is unable to determine if a union is constant
  2011-06-10 18:25 [Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant david.meggy at icron dot com
  2011-06-12 11:38 ` [Bug c/49368] " rguenth at gcc dot gnu.org
@ 2011-06-13 16:03 ` david.meggy at icron dot com
  1 sibling, 0 replies; 3+ messages in thread
From: david.meggy at icron dot com @ 2011-06-13 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from David Meggy <david.meggy at icron dot com> 2011-06-13 16:03:01 UTC ---
Both those versions are newer than what I'm using.  Looks like time to upgrade

Thanks for looking into this


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-13 16:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 18:25 [Bug c/49368] New: __builtin_constant_p is unable to determine if a union is constant david.meggy at icron dot com
2011-06-12 11:38 ` [Bug c/49368] " rguenth at gcc dot gnu.org
2011-06-13 16:03 ` david.meggy at icron dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).