public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/16377] New: -2147483648 -> 2147483648
@ 2013-12-28  9:35 ericjvandervelden at gmail dot com
  2013-12-28 13:20 ` [Bug gdb/16377] " ericjvandervelden at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: ericjvandervelden at gmail dot com @ 2013-12-28  9:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

            Bug ID: 16377
           Summary: -2147483648 -> 2147483648
           Product: gdb
           Version: 7.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: ericjvandervelden at gmail dot com

(gdb) p -2147483648
$51 = 2147483648

(gdb) pt -2147483648
type = unsigned int

Should be int. -2147483648 is een int.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug gdb/16377] -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
@ 2013-12-28 13:20 ` ericjvandervelden at gmail dot com
  2022-05-18 10:38 ` [Bug exp/16377] print " vries at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ericjvandervelden at gmail dot com @ 2013-12-28 13:20 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

Eric J. Van der Velden <ericjvandervelden at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ericjvandervelden at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
  2013-12-28 13:20 ` [Bug gdb/16377] " ericjvandervelden at gmail dot com
@ 2022-05-18 10:38 ` vries at gcc dot gnu.org
  2022-05-18 11:42 ` pedro at palves dot net
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-18 10:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|gdb                         |exp
                 CC|                            |vries at gcc dot gnu.org
            Summary|-2147483648 -> 2147483648   |print -2147483648 ->
                   |                            |2147483648

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
This is due to parsing the number and the sign separately.

It parses the number 2147483648, assigns type unsigned int to the expression
(since it doesn't fit in int), and then negates it, which for this particular
value is the identity operation.

Put differently, what you see is the result of" p -(2147483648)"

This behaviour is sort of documented at
https://sourceware.org/gdb/onlinedocs/gdb/C-Constants.html#C-Constants , in the
sense that the definition is "Integer constants are a sequence of digits" and
there's no mention of negative numbers or how '-' is interpreted.

My personal opinion is that this is not a feature but a bug, since it violates
the principle of least surprise.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
  2013-12-28 13:20 ` [Bug gdb/16377] " ericjvandervelden at gmail dot com
  2022-05-18 10:38 ` [Bug exp/16377] print " vries at gcc dot gnu.org
@ 2022-05-18 11:42 ` pedro at palves dot net
  2022-05-18 12:09 ` schwab@linux-m68k.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pedro at palves dot net @ 2022-05-18 11:42 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

Pedro Alves <pedro at palves dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pedro at palves dot net

--- Comment #2 from Pedro Alves <pedro at palves dot net> ---
GDB should follow the rules of language being parsed (C/C++).

E.g.: 

$ cat print1.c 
int
main ()
{
  auto i = -2147483648;
  i[0];
}
$ g++ print1.c -c -m64
print1.c: In function ‘void foo()’:
print1.c:4:4: error: invalid types ‘long int[int]’ for array subscript
    4 |   i[0];
      |    ^
$ g++ print1.c -c -m32
print1.c: In function ‘void foo()’:
print1.c:4:4: error: invalid types ‘long long int[int]’ for array subscript
    4 |   i[0];
      |    

Above we can see long for 64-bit, long long for 32-bit.  This is on x86-64
GNU/Linux.

Or, if you prefer something that compiles and runs:

$ cat print2.c 
#include <stdio.h>

#define WHICH(T)                                \
  void which (T l)                              \
  {                                             \
    printf (#T "\n");                           \
  }

WHICH(short)
WHICH(int)
WHICH(long)
WHICH(long long)

WHICH(unsigned short)
WHICH(unsigned int)
WHICH(unsigned long)
WHICH(unsigned long long)

int main ()
{
  which (-2147483648);
}

$ g++ print2.c -o print2.m64 -m64
$ g++ print2.c -o print2.m32 -m32
$ ./print2.m32 
long long
$ ./print2.m64
long

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (2 preceding siblings ...)
  2022-05-18 11:42 ` pedro at palves dot net
@ 2022-05-18 12:09 ` schwab@linux-m68k.org
  2022-05-18 13:07 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: schwab@linux-m68k.org @ 2022-05-18 12:09 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
See the comment in c-exp.y:parse_number:

      /* A large decimal (not hex or octal) constant (between INT_MAX
         and UINT_MAX) is a long or unsigned long, according to ANSI,
         never an unsigned int, but this code treats it as unsigned
         int.  This probably should be fixed.  GCC gives a warning on
         such constants.  */

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (3 preceding siblings ...)
  2022-05-18 12:09 ` schwab@linux-m68k.org
@ 2022-05-18 13:07 ` vries at gcc dot gnu.org
  2022-05-18 13:46 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-18 13:07 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Created attachment 14106
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14106&action=edit
WIP patch

FWIW, a patch I'm working on.

Doesn't apply cleanly, and probably also depends on a few other patches
submitted this week.

At least i386:x86_64 + language c works for the parse_number.exp test-case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (4 preceding siblings ...)
  2022-05-18 13:07 ` vries at gcc dot gnu.org
@ 2022-05-18 13:46 ` vries at gcc dot gnu.org
  2022-05-18 15:13 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-18 13:46 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Pedro Alves from comment #2)
> GDB should follow the rules of language being parsed (C/C++).

So I found some useful info here (
https://en.cppreference.com/w/cpp/language/integer_literal ).

This was news to me:
...
There are no negative integer literals. Expressions such as -1 apply the unary
minus operator to the value represented by the literal, which may involve
implicit type conversions. 
...

So I suppose the parser behaves as expected in this aspect: parsing number and
sign separately.

The problem is with the type of 2147483648.

There are (assuming no suffixes) two ways to assign a type to a constant.
Decimal bases vs Binary, octal, or hexadecimal bases.

The type of the integer literal is the first type in which the value can fit,
and the lists are:

Decimal base:
- int
- long int
- long long int
Binary, octal, or hexadecimal bases:
- int
- unsigned int
- long int
- unsigned long int
- long long int
- unsigned long long int


So we have with x86_64:
...
  which (2147483648);
  which (0x80000000);
...
types as expected:
...
long
unsigned int
...

But gdb does applies the rules for non-decimal base to decimal base:
...
$ ./gdb.sh -q -batch -ex "set arch i386:x86-64" -ex "ptype 2147483648" -ex
"ptype 0x80000000"The target architecture is set to "i386:x86-64".
type = unsigned int
type = unsigned int
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (5 preceding siblings ...)
  2022-05-18 13:46 ` vries at gcc dot gnu.org
@ 2022-05-18 15:13 ` vries at gcc dot gnu.org
  2022-05-18 17:39 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-18 15:13 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
Created attachment 14107
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14107&action=edit
Tentative patch

Tentative patch, currently testing.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (6 preceding siblings ...)
  2022-05-18 15:13 ` vries at gcc dot gnu.org
@ 2022-05-18 17:39 ` vries at gcc dot gnu.org
  2022-05-23 13:53 ` vries at gcc dot gnu.org
  2022-06-04 11:22 ` vries at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-18 17:39 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2022-May/189193.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (7 preceding siblings ...)
  2022-05-18 17:39 ` vries at gcc dot gnu.org
@ 2022-05-23 13:53 ` vries at gcc dot gnu.org
  2022-06-04 11:22 ` vries at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-05-23 13:53 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

--- Comment #8 from Tom de Vries <vries at gcc dot gnu.org> ---
Updated patch posted here:
https://sourceware.org/pipermail/gdb-patches/2022-May/189311.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug exp/16377] print -2147483648 -> 2147483648
  2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
                   ` (8 preceding siblings ...)
  2022-05-23 13:53 ` vries at gcc dot gnu.org
@ 2022-06-04 11:22 ` vries at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2022-06-04 11:22 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16377

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.1
         Resolution|---                         |FIXED

--- Comment #9 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1d8c0dfae79a5183e9e3311fb867afd679bc8e84

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2022-06-04 11:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-28  9:35 [Bug gdb/16377] New: -2147483648 -> 2147483648 ericjvandervelden at gmail dot com
2013-12-28 13:20 ` [Bug gdb/16377] " ericjvandervelden at gmail dot com
2022-05-18 10:38 ` [Bug exp/16377] print " vries at gcc dot gnu.org
2022-05-18 11:42 ` pedro at palves dot net
2022-05-18 12:09 ` schwab@linux-m68k.org
2022-05-18 13:07 ` vries at gcc dot gnu.org
2022-05-18 13:46 ` vries at gcc dot gnu.org
2022-05-18 15:13 ` vries at gcc dot gnu.org
2022-05-18 17:39 ` vries at gcc dot gnu.org
2022-05-23 13:53 ` vries at gcc dot gnu.org
2022-06-04 11:22 ` vries 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).