public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect
@ 2020-08-26  0:41 richard-gccbugzilla at metafoo dot co.uk
  2020-08-26  0:52 ` [Bug c/96788] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-08-26  0:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96788
           Summary: "integer constant is so large that it is unsigned"
                    warning is incorrect
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

Testcase:

  typedef __typeof(9223372036854775808LL) T;

produces the warning:

  <source>:1:18: warning: integer constant is so large that it is unsigned

for both C and C++ compilations, whether or not __int128 is available for the
target.

What actually appears to happen is that T is __int128 if __int128 is available,
and T is otherwise 'long long'.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
@ 2020-08-26  0:52 ` pinskia at gcc dot gnu.org
  2020-08-26  8:38 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-08-26  0:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
__int128 should not be used with respect to the type at all.  __int128  is NOT
extended integer type:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50441

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
  2020-08-26  0:52 ` [Bug c/96788] " pinskia at gcc dot gnu.org
@ 2020-08-26  8:38 ` redi at gcc dot gnu.org
  2020-08-26 18:47 ` richard-gccbugzilla at metafoo dot co.uk
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-26  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> __int128  is NOT extended integer type:

WG14 are supposed to be fixing that though.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
  2020-08-26  0:52 ` [Bug c/96788] " pinskia at gcc dot gnu.org
  2020-08-26  8:38 ` redi at gcc dot gnu.org
@ 2020-08-26 18:47 ` richard-gccbugzilla at metafoo dot co.uk
  2020-08-26 18:49 ` richard-gccbugzilla at metafoo dot co.uk
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-08-26 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
In the mean time, what is GCC's intent here? Clang is following the behavior
described by GCC's diagnostic text, treating decimal integer literals that
don't fit in 'long long' but do fit in 'unsigned long long' as the latter type
(I've not checked back far enough to tell if this is what GCC ever actually
did, or if we got this by looking at the diagnostics and didn't check the
behavior). If that's not what GCC intends to do any more, that'd be useful for
us to know, and we can switch to following GCC's actual behavior. (It'd also
make sense to update the diagnostic text in that case!)

It looks like both the Clang behavior (treat the literal as 'unsigned long
long') and the GCC behavior (treat the literal as '__int128' where available
and 'long long' otherwise) are conforming extensions in both C and C++, even
though __int128 isn't (yet) an extended integer type: such a literal "has no
type" in C, which presumably results in undefined behavior, and makes the
program ill-formed in C++, so it seems there is room for a vendor extension in
both languages.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
                   ` (2 preceding siblings ...)
  2020-08-26 18:47 ` richard-gccbugzilla at metafoo dot co.uk
@ 2020-08-26 18:49 ` richard-gccbugzilla at metafoo dot co.uk
  2020-08-26 22:55 ` joseph at codesourcery dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-08-26 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
(In reply to Richard Smith from comment #3)
> such a literal "has no type" in C, which presumably results in undefined
> behavior

Ah, no, C11 6.4.4/2 makes this a constraint violation. But either way I think
there's room for a vendor extension here.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
                   ` (3 preceding siblings ...)
  2020-08-26 18:49 ` richard-gccbugzilla at metafoo dot co.uk
@ 2020-08-26 22:55 ` joseph at codesourcery dot com
  2020-11-19 23:04 ` pascal_cuoq at hotmail dot com
  2023-08-08 10:18 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: joseph at codesourcery dot com @ 2020-08-26 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
The way GCC actually behaves is that this constant is unsigned in the 
preprocessor but signed outside the preprocessor.  I'm not sure that's 
exactly intent (though the preprocessor having only a single signed and 
unsigned type, with this constant not fitting in the signed type, means it 
couldn't be interpreted as signed in the preprocessor if allowed in #if 
expressions at all).  The warnings are attempting to cover both the C90 
case where a decimal constant too large for signed long can be unsigned 
long, and the case of a constant too large for intmax_t.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
                   ` (4 preceding siblings ...)
  2020-08-26 22:55 ` joseph at codesourcery dot com
@ 2020-11-19 23:04 ` pascal_cuoq at hotmail dot com
  2023-08-08 10:18 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pascal_cuoq at hotmail dot com @ 2020-11-19 23:04 UTC (permalink / raw)
  To: gcc-bugs

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

Pascal Cuoq <pascal_cuoq at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pascal_cuoq at hotmail dot com

--- Comment #6 from Pascal Cuoq <pascal_cuoq at hotmail dot com> ---
Joseph Myers wrote:
> The warnings are attempting to cover both the C90 
> case where a decimal constant too large for signed long can be unsigned 
> long, and the case of a constant too large for intmax_t.

In the case of the constant 10000000000000000000, each of the two kind of
warnings, “ integer constant is so large that it is unsigned” and “this decimal
constant is unsigned only in ISO C90” can be misleading.

Consider the compilation unit:

int x;

void f(void) {
    x = -10000000000000000000 < 0;
}

1/ Misleading warning “this decimal constant is unsigned only in ISO C90”

Compiler Explorer link: https://gcc.godbolt.org/z/4Eze1f

Using GCC 10.2 targeting x86, the compilation options “-O -m32 -std=c89” make
GCC compile f as below, and emit the warning “this decimal constant is unsigned
only in ISO C90”

f:
        movl    $0, x
        ret

Actually, changing the C dialect to C99 does not make the constant not
unsigned, since GCC emits the same assembly code for f (setting x to 0) with
“-O -m32 -std=c99”

2/ Misleading warning “integer constant is so large that it is unsigned”

Compiler Explorer link: https://gcc.godbolt.org/z/MGjn5G

Using GCC 10.2 targeting x86, the compilation options “-O -m64 -std=c99” make
GCC compile f as below, and emit the warning “integer constant is so large that
it is unsigned”.

f:
        movl    $1, x(%rip)
        ret

The constant is not unsigned. If it were, the function f would not set x to 1.

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

* [Bug c/96788] "integer constant is so large that it is unsigned" warning is incorrect
  2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
                   ` (5 preceding siblings ...)
  2020-11-19 23:04 ` pascal_cuoq at hotmail dot com
@ 2023-08-08 10:18 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-08 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=84764

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Is this a dup of PR 84764?

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

end of thread, other threads:[~2023-08-08 10:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26  0:41 [Bug c/96788] New: "integer constant is so large that it is unsigned" warning is incorrect richard-gccbugzilla at metafoo dot co.uk
2020-08-26  0:52 ` [Bug c/96788] " pinskia at gcc dot gnu.org
2020-08-26  8:38 ` redi at gcc dot gnu.org
2020-08-26 18:47 ` richard-gccbugzilla at metafoo dot co.uk
2020-08-26 18:49 ` richard-gccbugzilla at metafoo dot co.uk
2020-08-26 22:55 ` joseph at codesourcery dot com
2020-11-19 23:04 ` pascal_cuoq at hotmail dot com
2023-08-08 10:18 ` redi at gcc dot gnu.org

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).