[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
This commit is contained in:
parent
1b4633f812
commit
1d8c0dfae7
4 changed files with 130 additions and 76 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue