public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98418] New: Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants
@ 2020-12-22 10:47 pskocik at gmail dot com
  2020-12-22 10:50 ` [Bug c/98418] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pskocik at gmail dot com @ 2020-12-22 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98418

            Bug ID: 98418
           Summary: Valid integer constant expressions based on
                    expressions that trigger -Wshift-overflow are treated
                    as non-constants
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

This causes things like:

struct foo { unsigned bit: (0xffffffffll<<40)!=0; };

to elicit a -pedantic warning about the bitfield width not being a proper
integer constant expression, even though it is.

In other contexts, a complete compilation error might ensue:

extern int bar[ (0xffffffffll<<40)!=0 ]; //seen as an invalid VLA


https://gcc.godbolt.org/z/7zfz96

Neither clang nor gcc <= 5 appear to have this bug.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93241 seems related.

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

* [Bug c/98418] Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants
  2020-12-22 10:47 [Bug c/98418] New: Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants pskocik at gmail dot com
@ 2020-12-22 10:50 ` pinskia at gcc dot gnu.org
  2020-12-24 18:53 ` pskocik at gmail dot com
  2020-12-24 18:55 ` pskocik at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-22 10:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98418

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Shifting into the sign bit is problematic. I cant remember the exact rules.
Using ull is valid though.

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

* [Bug c/98418] Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants
  2020-12-22 10:47 [Bug c/98418] New: Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants pskocik at gmail dot com
  2020-12-22 10:50 ` [Bug c/98418] " pinskia at gcc dot gnu.org
@ 2020-12-24 18:53 ` pskocik at gmail dot com
  2020-12-24 18:55 ` pskocik at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pskocik at gmail dot com @ 2020-12-24 18:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98418

--- Comment #2 from pskocik at gmail dot com ---
You're right. The bug was in my code.

struct foo { unsigned bit: (0xffffffffll<<40)!=0; };

is indeed UB due to http://port70.net/~nsz/c/c11/n1570.html#6.5.7p4, but

struct foo { unsigned bit: (0xffffffffull<<40)!=0; };

isn't and GCC accepts it without complaint.

Apologies for the false alarm.

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

* [Bug c/98418] Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants
  2020-12-22 10:47 [Bug c/98418] New: Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants pskocik at gmail dot com
  2020-12-22 10:50 ` [Bug c/98418] " pinskia at gcc dot gnu.org
  2020-12-24 18:53 ` pskocik at gmail dot com
@ 2020-12-24 18:55 ` pskocik at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pskocik at gmail dot com @ 2020-12-24 18:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98418

pskocik at gmail dot com changed:

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

--- Comment #3 from pskocik at gmail dot com ---
You're right. The bug was in my code.

struct foo { unsigned bit: (0xffffffffll<<40)!=0; };

is indeed UB due to http://port70.net/~nsz/c/c11/n1570.html#6.5.7p4, but

struct foo { unsigned bit: (0xffffffffull<<40)!=0; };

isn't and GCC accepts it without complaint.

Apologies for the false alarm.

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

end of thread, other threads:[~2020-12-24 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 10:47 [Bug c/98418] New: Valid integer constant expressions based on expressions that trigger -Wshift-overflow are treated as non-constants pskocik at gmail dot com
2020-12-22 10:50 ` [Bug c/98418] " pinskia at gcc dot gnu.org
2020-12-24 18:53 ` pskocik at gmail dot com
2020-12-24 18:55 ` pskocik at gmail 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).