From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1930) id 9F5F23857C77; Sat, 13 Mar 2021 21:29:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F5F23857C77 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Sebor To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-7658] PR tree-optimization/99489 - ICE calling strncat after strcat X-Act-Checkin: gcc X-Git-Author: Martin Sebor X-Git-Refname: refs/heads/master X-Git-Oldrev: 7987beec679898cfa75839551d55ae5234a216bd X-Git-Newrev: 77643ac4bbd0ff758edc182a12cb622b74a3c38a Message-Id: <20210313212949.9F5F23857C77@sourceware.org> Date: Sat, 13 Mar 2021 21:29:49 +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: Sat, 13 Mar 2021 21:29:49 -0000 https://gcc.gnu.org/g:77643ac4bbd0ff758edc182a12cb622b74a3c38a commit r11-7658-g77643ac4bbd0ff758edc182a12cb622b74a3c38a Author: Martin Sebor Date: Tue Mar 9 15:02:35 2021 -0700 PR tree-optimization/99489 - ICE calling strncat after strcat gcc/ChangeLog: PR tree-optimization/99489 * builtins.c (gimple_call_alloc_size): Fail gracefully when argument is not a call statement. gcc/testsuite/ChangeLog: PR tree-optimization/99489 * gcc.dg/Wstringop-truncation-9.c: New test. Diff: --- gcc/builtins.c | 2 +- gcc/testsuite/gcc.dg/Wstringop-truncation-9.c | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 41e336c071c..196dda3fa5e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4924,7 +4924,7 @@ tree gimple_call_alloc_size (gimple *stmt, wide_int rng1[2] /* = NULL */, range_query * /* = NULL */) { - if (!stmt) + if (!stmt || !is_gimple_call (stmt)) return NULL_TREE; tree allocfntype; diff --git a/gcc/testsuite/gcc.dg/Wstringop-truncation-9.c b/gcc/testsuite/gcc.dg/Wstringop-truncation-9.c new file mode 100644 index 00000000000..63614809da4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-truncation-9.c @@ -0,0 +1,41 @@ +/* PR tree-optimization/99489 - ICE calling strncat after strncat + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +// Important -- see pr82429. +char *stpcpy (char *, const char *); + +void fchar (char *d, char c, char *s) +{ + __builtin_strcat (d, s); + __builtin_strncat (d, &c, 1); +} + +void fcstchar (char *d, char *s) +{ + __builtin_strcat (d, s); + + const char c = 'x'; + __builtin_strncat (d, &c, 1); // { dg-warning "-Wstringop-truncation" } +} + +void fstr (char *d, char *s) +{ + __builtin_strcat (d, s); + __builtin_strncat (d, s, 1); +} + +void farr (char *d, char *s) +{ + __builtin_strcat (d, s); + + char a[] = "x"; + __builtin_strncat (d, a, 1); // { dg-warning "-Wstringop-truncation" } +} + +void flit (char *d, char *s) +{ + __builtin_strcat (d, s); + __builtin_strncat (d, "x", 1); // { dg-warning "-Wstringop-truncation" "pr?????" { xfail *-*-*} } + // { dg-warning "-Wstringop-overflow" "actual" { target *-*-*} .-1 } +}