From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id CB262385B50B; Fri, 23 Dec 2022 14:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB262385B50B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671805753; bh=h8W7HCJljsC7tpXbTFin6NLKs6rN0lSaH6ktkWQ+H18=; h=From:To:Subject:Date:From; b=H+nExlvaX7PH7fm/nuowzml4MrMvkbDtX+DFAz4KH14QROItyo+JVmFHAksvxTff+ G6G32NVAppU6jexnQ86a5iGbKTCFECuMUpqhhG0DkKLKRBOlEzIZjA24zGcCHT8Xuv uC+zdxNl6syCyWWMwisAjHsg6xFzPVFPtJYPMrb8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/PR108137-strlen-ice)] strlen: do not use cond_expr for boundaries X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/PR108137-strlen-ice X-Git-Oldrev: b358521b608f36409281a51263ace3155d28f54d X-Git-Newrev: 3fbc10fa6b6aa2c264905af5f55c36c021ea0f99 Message-Id: <20221223142913.CB262385B50B@sourceware.org> Date: Fri, 23 Dec 2022 14:29:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3fbc10fa6b6aa2c264905af5f55c36c021ea0f99 commit 3fbc10fa6b6aa2c264905af5f55c36c021ea0f99 Author: Martin Liska Date: Fri Dec 23 15:27:32 2022 +0100 strlen: do not use cond_expr for boundaries PR tree-optimization/108137 gcc/ChangeLog: * tree-ssa-strlen.cc (get_range_strlen_phi): Reject anything different from INTEGER_CST. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr108137.c: New test. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/pr108137.c | 8 ++++++++ gcc/tree-ssa-strlen.cc | 13 +++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108137.c b/gcc/testsuite/gcc.dg/tree-ssa/pr108137.c new file mode 100644 index 00000000000..f0cb71b2267 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108137.c @@ -0,0 +1,8 @@ +// PR tree-optimization/108137 +// { dg-do compile } +// { dg-options "-Wformat-overflow" } + +void f(unsigned short x_port, unsigned int x_host) +{ + __builtin_printf("missing %s", x_port ? "host" : &"host:port"[x_host ? 5 : 0]); +} diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index abec225566d..a2edac4c77f 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -1136,14 +1136,15 @@ get_range_strlen_phi (tree src, gphi *phi, /* Adjust the minimum and maximum length determined so far and the upper bound on the array size. */ - if (!pdata->minlen - || tree_int_cst_lt (argdata.minlen, pdata->minlen)) + if (TREE_CODE (argdata.minlen) == INTEGER_CST + && (!pdata->minlen + || tree_int_cst_lt (argdata.minlen, pdata->minlen))) pdata->minlen = argdata.minlen; - if (!pdata->maxlen - || (argdata.maxlen - && TREE_CODE (argdata.maxlen) == INTEGER_CST - && tree_int_cst_lt (pdata->maxlen, argdata.maxlen))) + if (TREE_CODE (argdata.maxlen) == INTEGER_CST + && (!pdata->maxlen + || (argdata.maxlen + && tree_int_cst_lt (pdata->maxlen, argdata.maxlen)))) pdata->maxlen = argdata.maxlen; if (!pdata->maxbound