diff options
author | Tom de Vries <tdevries@suse.de> | 2022-06-04 13:17:33 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-06-04 13:17:33 +0200 |
commit | 1d8c0dfae79a5183e9e3311fb867afd679bc8e84 (patch) | |
tree | 2415ed745f9dc5a2828564fe0e90af01b93fcadb /gdb/parser-defs.h | |
parent | 1b4633f812b329863a523c4d798c2b55417b5144 (diff) | |
download | gdb-1d8c0dfae79a5183e9e3311fb867afd679bc8e84.zip gdb-1d8c0dfae79a5183e9e3311fb867afd679bc8e84.tar.gz gdb-1d8c0dfae79a5183e9e3311fb867afd679bc8e84.tar.bz2 |
[gdb/c] Fix type of 2147483648 and literal truncation
[ Assuming arch i386:x86-64, sizeof (int) == 4,
sizeof (long) == sizeof (long long) == 8. ]
Currently we have (decimal for 0x80000000):
...
(gdb) ptype 2147483648
type = unsigned int
...
According to C language rules, unsigned types cannot be used for decimal
constants, so the type should be long instead (reported in PR16377).
Fix this by making sure the type of 2147483648 is long.
The next interesting case is (decimal for 0x8000000000000000):
...
(gdb) ptype 9223372036854775808
type = unsigned long
...
According to the same rules, unsigned long is incorrect.
Current gcc uses __int128 as type, which is allowed, but we don't have that
available in gdb, so the strict response here would be erroring out with
overflow.
Older gcc without __int128 support, as well as clang use an unsigned type, but with
a warning. Interestingly, clang uses "unsigned long long" while gcc uses
"unsigned long", which seems the better choice.
Given that the compilers allow this as a convience, do the same in gdb
and keep type "unsigned long", and make this explicit in parser and test-case.
Furthermore, make sure we error out on overflow instead of truncating in all
cases.
Tested on x86_64-linux with --enable-targets=all.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16377
Diffstat (limited to 'gdb/parser-defs.h')
-rw-r--r-- | gdb/parser-defs.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 3be7d6c..ade3039 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -412,6 +412,8 @@ extern std::string copy_name (struct stoken); extern bool parse_float (const char *p, int len, const struct type *type, gdb_byte *data); +extern bool fits_in_type (int n_sign, ULONGEST n, int type_bits, + bool type_signed_p); /* Function used to avoid direct calls to fprintf |