From patchwork Fri Dec 23 15:44:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 36301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp385733wrn; Fri, 23 Dec 2022 07:44:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXvCyUCWknb4cCRp8wayHe50XysbjbM6vqtH4kDA71Jmr6yDj3Ycj9o+EJiTPc0TuTKof9BV X-Received: by 2002:a05:6402:299b:b0:480:cbe7:9ee2 with SMTP id eq27-20020a056402299b00b00480cbe79ee2mr3193847edb.22.1671810275143; Fri, 23 Dec 2022 07:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671810275; cv=none; d=google.com; s=arc-20160816; b=Eb5r+X//RzyWm5cDzpkAqcMq6h16nOzWAxGjDhM1QV+uZXkgM+nB9T0OxiDlp4z2yw u7fXeeybIaBV6bD5k/7ajFlbdJwgwzBSc2i01HdL0hhXy/96054KtL+1TeIMyjucdaZj hcrwF0BOC4csjjr6oTianqYJ1w48NKhobqTOTZxGYSMhBIJGpBYNc/wey0FNuukb6vYu VTZKI03Mt0v2x3xNmlhKEcpU1BrTfUKMhp4zn2SxKBq2o8Ix929t8k4CpBu1A7fAnfnu 5HDKc8XDEg86PWhFNQEQPgLUnO8Ayl+bqN/RWMfa8ZJAuCPtBkMy9VEiz6sLaDhw/Ijb CJ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding:cc :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=RdmvtR0oX8oGwxg3B3uxLN//PpaJeav2UpPZo0RlS6U=; b=qKPa5K4HpY3xgj8YMCFuEUVgLVy2Q2g6xjiWh7K1mIp65KqNph4Dktp+uBltaKx9yS WPuLCsssNkyoEbcKnY7HSvHXRBXj+mtFdvxiGJ3x9Hw4RrvPegmj7OwHyRLso3MbVUUg tZDb1evUkdmvfxusdK7oixo9Ni1pMkTrh/vPAEtYCbQQfOZ+9O3i0LeJURoB3T3UstFn Siz4do7YfQ1VG9NCVJqTow2WiiqbMJ+QLXDue+uoXMvhp/E7fjRQAzypfYu+tlkASF/a jpAP0u1I4jdl8Qq79FvNZFstXLy1dWB7qvFBJ2uRFAy4TS2Xs9Z1CGTQHxRHp0XTvBVj m88g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="Ao/ysv9x"; dkim=neutral (no key) header.i=@suse.cz header.b="c/9nQbLj"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q12-20020a056402518c00b0046c0f2a94dbsi3348108edd.353.2022.12.23.07.44.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 07:44:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="Ao/ysv9x"; dkim=neutral (no key) header.i=@suse.cz header.b="c/9nQbLj"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A6B63850F05 for ; Fri, 23 Dec 2022 15:44:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 732E03858D1E for ; Fri, 23 Dec 2022 15:44:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 732E03858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5AC4C6B198; Fri, 23 Dec 2022 15:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671810245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RdmvtR0oX8oGwxg3B3uxLN//PpaJeav2UpPZo0RlS6U=; b=Ao/ysv9x48U+G6MlZ5et6TE2EOG/j9nQ3igAPT7zioDuxIAIckbrWdYDKb/wDC3B7NgeZR kFuDYWcLCoaPveFVQhety3bA+NLV/Vur3T1H+kdqTMbnvJiSHS+L5N7LCjIByr4rbCz2v4 hlvL6CJp0NlBx9Equ6LsLqpXZU5ao+4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671810245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RdmvtR0oX8oGwxg3B3uxLN//PpaJeav2UpPZo0RlS6U=; b=c/9nQbLj7OnAwj3kAngLhfBxf/jfU7hNTRmbd2pMJBjxY3nB4hOz1/ESIh37f+g3vTx761 KIS+2jMcFFlk2MBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 466DB13913; Fri, 23 Dec 2022 15:44:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jmQwEMXMpWP5CAAAMHmgww (envelope-from ); Fri, 23 Dec 2022 15:44:05 +0000 Message-ID: <677e6b2b-5198-f2b2-d5e5-dc388b77bcb0@suse.cz> Date: Fri, 23 Dec 2022 16:44:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] strlen: do not use cond_expr for boundaries To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: Martin Sebor X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753020130865183405?= X-GMAIL-MSGID: =?utf-8?q?1753020130865183405?= Hi. We reach cond_expr and then we get an ICE in tree_int_cst_lt. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin 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. --- gcc/testsuite/gcc.dg/tree-ssa/pr108137.c | 8 ++++++++ gcc/tree-ssa-strlen.cc | 13 +++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108137.c 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