From patchwork Mon Mar 28 13:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 52403 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 448673898C74 for ; Mon, 28 Mar 2022 13:17:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 448673898C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648473434; bh=ezkLQSh4QLSVN4glDQnLKR/pP6ZbN24fFGROiAIfXa8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=chbvnwEuC2FaJD2qNesxg7uMfxmoBM/so/9ITa5LEaLvA0JE2hQ+Jc0BuWtGHvJtx diqA6FI1p9LiQvwno9jAoastnW/7bbVZo0vzAOSA8No1n8rr4mnjRypHrIoeOP/Fpt Xeb5BwlJkrvGDQfPOp+pHkpwt/uoY64ARZ3WGFPI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E6B4C389A100 for ; Mon, 28 Mar 2022 13:16:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6B4C389A100 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-out2.suse.de (Postfix) with ESMTPS id 22E0A1F381; Mon, 28 Mar 2022 13:16:25 +0000 (UTC) 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 05BFC13215; Mon, 28 Mar 2022 13:16:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DLpeACm1QWKfEwAAMHmgww (envelope-from ); Mon, 28 Mar 2022 13:16:25 +0000 Date: Mon, 28 Mar 2022 15:16:24 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/105080 - make sure SCEV is available for ranger MIME-Version: 1.0 Message-Id: <20220328131625.05BFC13215@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: Jakub Jelinek , msebor@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When doing format diagnostics at -O0 we should make sure to make SCEV available to avoid false positives due to ranges we otherwise can trivially compute. Bootstrap and regtest running on x86_64-unknown-linux-gnu. OK if that succeeds? Thanks, Richard. 2022-03-28 Richard Biener PR tree-optimization/105080 * tree-ssa-strlen.cc (printf_strlen_execute): Always init loops and SCEV. * gcc.dg/pr105080.c: New testcase. --- gcc/testsuite/gcc.dg/pr105080.c | 11 +++++++++++ gcc/tree-ssa-strlen.cc | 16 ++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr105080.c diff --git a/gcc/testsuite/gcc.dg/pr105080.c b/gcc/testsuite/gcc.dg/pr105080.c new file mode 100644 index 00000000000..77ee7eeb396 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105080.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -Wall" } */ + +int main() +{ + char foo[3]; + int i; + + for (i = 0; i < 16; i++) + __builtin_snprintf(foo, sizeof(foo), "%d", i); /* { dg-bogus "truncated" } */ +} diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index 112f0dce874..b2556366214 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -5858,13 +5858,8 @@ printf_strlen_execute (function *fun, bool warn_only) strlen_optimize = !warn_only; calculate_dominance_info (CDI_DOMINATORS); - - bool use_scev = optimize > 0 && flag_printf_return_value; - if (use_scev) - { - loop_optimizer_init (LOOPS_NORMAL); - scev_initialize (); - } + loop_optimizer_init (LOOPS_NORMAL); + scev_initialize (); gcc_assert (!strlen_to_stridx); if (warn_stringop_overflow || warn_stringop_truncation) @@ -5902,11 +5897,8 @@ printf_strlen_execute (function *fun, bool warn_only) strlen_to_stridx = NULL; } - if (use_scev) - { - scev_finalize (); - loop_optimizer_finalize (); - } + scev_finalize (); + loop_optimizer_finalize (); return walker.m_cleanup_cfg ? TODO_cleanup_cfg : 0; }