[PATCH] Make out of range type conversions explicit
Pedro Alves
pedro@palves.net
Thu Jul 2 20:23:52 GMT 2020
On 6/30/20 2:58 PM, Gary Benson via Gdb-patches wrote:
> HI all,
>
> Clang fails to compile two testcases with the following warning:
> implicit conversion from 'X' to 'Y' changes value from x to y
> [-Wconstant-conversion]. This patch adds casts that make the
> value-changing conversions explicit.
It's helpful if you show the full error. Like:
gdb compile failed, /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/charset.c:144:20: warning:
implicit conversion from 'int' to 'char' changes value from 162 to -94
[-Wconstant-conversion]
11, 162, 17);
^~~
/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/charset.c:151:16: warning:
implicit conversion from 'int' to 'char' changes value from 167 to -89
[-Wconstant-conversion]
167,
^~~
/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/charset.c:168:16: warning:
implicit conversion from 'int' to 'char' changes value from 167 to -89
[-Wconstant-conversion]
167,
^~~
3 warnings generated.
=== gdb Summary ===
# of untested testcases 1
Above, I think a better fix would be to change init_string to take
unsigned char parameters, since we're really passing down raw bytes.
The other one is:
~~~~~~
gdb compile failed, /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/structs2.c:16:14: warning:
implicit conversion from 'int' to 'signed char' changes value from 130 to
-126 [-Wconstant-conversion]
param_reg (130, 120, 33000, 32000);
~~~~~~~~~ ^~~
/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/structs2.c:16:24: warning:
implicit conversion from 'int' to 'short' changes value from 33000 to
-32536 [-Wconstant-conversion]
param_reg (130, 120, 33000, 32000);
~~~~~~~~~ ^~~~~
2 warnings generated.
WARNING: Prototypes not supported, rebuilding with -DNO_PROTOTYPES
gdb compile failed, /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/structs2.c:16:14: warning:
implicit conversion from 'int' to 'signed char' changes value from 130 to
-126 [-Wconstant-conversion]
param_reg (130, 120, 33000, 32000);
~~~~~~~~~ ^~~
/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/structs2.c:16:24: warning:
implicit conversion from 'int' to 'short' changes value from 33000 to
-32536 [-Wconstant-conversion]
param_reg (130, 120, 33000, 32000);
~~~~~~~~~ ^~~~~
2 warnings generated.
=== gdb Summary ===
# of untested testcases 1
~~~~~~
Here, param_reg's prototype is:
static void param_reg (register signed char pr_char,
register unsigned char pr_uchar,
register short pr_short,
register unsigned short pr_ushort);
pr_char and pr_short are signed, so how about just passing
down negative numbers. That's what the testcase expects
GDB will show:
gdb_test "continue" \
".*pr_char=-126.*pr_uchar=120.*pr_short=-32536.*pr_ushort=32000.*bkpt = 1.*" \
"structs2 continue2"
I think it's best to push fix each testcase in its own commit.
See patches attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-gdb.base-charset.exp-with-Clang.patch
Type: text/x-patch
Size: 2193 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/gdb-patches/attachments/20200702/07776bb5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-gdb.base-structs2.exp-with-Clang.patch
Type: text/x-patch
Size: 1973 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/gdb-patches/attachments/20200702/07776bb5/attachment-0001.bin>
More information about the Gdb-patches
mailing list