From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E930A384BC11; Mon, 31 May 2021 14:08:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E930A384BC11 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8489] builtins: Fix ICE with unprototyped builtin call [PR100576] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 490ffb47ad10df1793c4894c7c888d7a10576f1a X-Git-Newrev: f4d6ea0c64bbbbe45add18294bfbd2ceb6512bbd Message-Id: <20210531140838.E930A384BC11@sourceware.org> Date: Mon, 31 May 2021 14:08:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 14:08:39 -0000 https://gcc.gnu.org/g:f4d6ea0c64bbbbe45add18294bfbd2ceb6512bbd commit r11-8489-gf4d6ea0c64bbbbe45add18294bfbd2ceb6512bbd Author: Jakub Jelinek Date: Wed May 19 12:05:30 2021 +0200 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 ‘’ or provide a declaration of ‘memcmp’ +++ |+#include 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 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. (cherry picked from commit e6683450f4a26dae7774be735a3429f48aee9565) Diff: --- gcc/builtins.c | 2 ++ gcc/testsuite/gcc.c-torture/compile/pr100576.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/gcc/builtins.c b/gcc/builtins.c index d30c4eb62fc..308846ee39b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4910,6 +4910,8 @@ check_read_access (tree exp, tree src, tree bound /* = NULL_TREE */, if (!warn_stringop_overread) return true; + if (bound && !useless_type_conversion_p (size_type_node, TREE_TYPE (bound))) + bound = fold_convert (size_type_node, bound); access_data data (exp, access_read_only, NULL_TREE, false, bound, true); compute_objsize (src, ost, &data.src); return check_access (exp, /*dstwrite=*/ NULL_TREE, /*maxread=*/ bound, diff --git a/gcc/testsuite/gcc.c-torture/compile/pr100576.c b/gcc/testsuite/gcc.c-torture/compile/pr100576.c new file mode 100644 index 00000000000..f2f40ec4512 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr100576.c @@ -0,0 +1,12 @@ +/* PR middle-end/100576 */ + +const char v[] = {0x12}; + +void +foo (const char *p) +{ + int b = sizeof v; + int n = memcmp (p, v, b); + if (n) + __builtin_abort (); +}