builtins: Fix ICE with unprototyped builtin call [PR100576]
authorJakub Jelinek <jakub@redhat.com>
Wed, 19 May 2021 10:05:30 +0000 (12:05 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 19 May 2021 10:05:30 +0000 (12:05 +0200)
commite6683450f4a26dae7774be735a3429f48aee9565
treed5f7a3155133bc1f9ca4b0f6f43a5f98f140c572
parenta73a5af281cebd03bbd37f37eef9a8a91b5fbf95
builtins: Fix ICE with unprototyped builtin call [PR100576]

For unprototyped builtins the checking we perform is only about whether
the used argument is integral, pointer etc., not the exact precision.
We emit a warning about the problem though:
pr100576.c: In function ‘foo’:
pr100576.c:9:11: warning: implicit declaration of function ‘memcmp’ [-Wimplicit-function-declaration]
    9 |   int n = memcmp (p, v, b);
      |           ^~~~~~
pr100576.c:1:1: note: include ‘<string.h>’ or provide a declaration of ‘memcmp’
  +++ |+#include <string.h>
    1 | /* PR middle-end/100576 */
pr100576.c:9:25: warning: ‘memcmp’ argument 3 type is ‘int’ where ‘long unsigned int’ is expected in a call to built-in function declared without prototype
+[-Wbuiltin-declaration-mismatch]
    9 |   int n = memcmp (p, v, b);
      |                         ^
It means in the testcase below where the user incorrectly called memcmp
with last argument int rather then size_t, the warning stuff in builtins.c
ICEs because it compares a wide_int from such a bound with another wide_int
which has precision of size_t/sizetype and wide_int asserts the compared
wide_ints are compatible.

Fixed by forcing the bound to have the right type.

2021-05-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/100576
* builtins.c (check_read_access): Convert bound to size_type_node if
non-NULL.

* gcc.c-torture/compile/pr100576.c: New test.
gcc/builtins.c
gcc/testsuite/gcc.c-torture/compile/pr100576.c [new file with mode: 0644]