From patchwork Tue May 28 18:56:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1940678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eSW3xQdx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VphZf2FJHz20Pq for ; Wed, 29 May 2024 04:56:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F5B6384B434 for ; Tue, 28 May 2024 18:56:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0196E3865C28 for ; Tue, 28 May 2024 18:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0196E3865C28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0196E3865C28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716922578; cv=none; b=Bdc1GprJNiMOC3GAWlo8ezSTxiyijwbIj0VEO126Y3xXa1ScEHvdUf/1MF7x2cNSUJwpWG83mlq7vPQjOFs1YkoKJ2acASQ0GtNue2/AedKJ2LLIiMZyO0nPRcNoNoE8sNUrbXCPeMScAnyvCrA9QG0nMSfP1OMllPmQEaQAItU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716922578; c=relaxed/simple; bh=DPFVwM2EvvXQykKcSQhxurbcG7uugIXjLUZRiUFF1FE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=V+yRQmFXoi1gBwH4FfP3a+sXLtSEatT3LhkcUhp7u+KMzk2uD2DXfOKvsQtmjoEyi5gHKoFgDmCM1pG8jUD7OV3wsOglveQE8w8tnCOygUX0rMLfQvMXd+Us10rotKZLjMIT6dYSRciCr59Qpyhu3mBEkDNmDwx0SXuivYN/tUE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716922575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1esdF0kI8r0HaQsI/fUe/6i35d6TsGCn9X4SmIHQGc8=; b=eSW3xQdxVYCrbFQlqVk3+Lk5wvoxDpT3M5YWy5MXOrM/B07ySMpuVYTZ9PLNIfpDbAnizd 6IcWzWrBaHD/gq3+SLdmmyjNGbHbPhy+BOhU04uhd8H+rsbYjqTbUWt4uXz2gt6RTVgIRo XwODjOoC5OpNb4NY1kIGL2TTccwtEWw= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-5E55rd0aNLSwTYBiFoxGag-1; Tue, 28 May 2024 14:56:13 -0400 X-MC-Unique: 5E55rd0aNLSwTYBiFoxGag-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-43faa4d2080so8955891cf.0 for ; Tue, 28 May 2024 11:56:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716922573; x=1717527373; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aA5nxid6z8g4SlpBA5vBS3RNwjfBzcjb9tNcMwI9rlE=; b=wKxU4iY1R1SxJiFOU67Up87jG5dwkUVwVwJV3f/PGYKO0JBuEjORug6Op8YLlXyxhQ LY4XTmIoNpcEvENVi3w6THlvx1bfa3toQeq2Gnc/iic9F+K0WU2XvKpLtY5qjNDYIMZn v2r9drUlFdTDTV5rF3a2J56zNUEwDkiIgHM2NnvSevWpIHW0CD6ceiOEceZxsIGxAW2p IuGGvQpWIpClvY7Qy/Khpug4iFlC4Xjhgmq/t82sq/Ze6zKzVJVigxP1qm9Hwy5gCB1H Yl1uvWLU51jSPabdT4po3dbYP93SdYoPEndp06uzZ54o93SsZRBqgfZxSknZAf1IyU0E 9jQg== X-Gm-Message-State: AOJu0YyEE/IeB2CiSdbL07mZ+HXpjn6yVrDcGB6q5XYNCBeLvPrWl1wT ssm8j1p9YjmVn5CzRLRmviyM5WYQP6wO1HIHjpU4FAuwkT5l4fhedFS+CyEtEzCakiHJ1sKVqjN FZDRzDOrgrnTmaxvpQDY232OdQE+boPSMn6fO73fonruXgvq+5wqJo+k= X-Received: by 2002:a05:622a:612:b0:43a:b9c9:a25c with SMTP id d75a77b69052e-43fb0e80667mr166980231cf.38.1716922572794; Tue, 28 May 2024 11:56:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVHD4lEx1j69jD9iTV3pfnz58YSABtDcmudWofJ8gKNAoRtpc3oLlCfWHfH0ful06Pd5OIrw== X-Received: by 2002:a05:622a:612:b0:43a:b9c9:a25c with SMTP id d75a77b69052e-43fb0e80667mr166979891cf.38.1716922572111; Tue, 28 May 2024 11:56:12 -0700 (PDT) Received: from ?IPV6:2607:fea8:51db:5900::9ff8? ([2607:fea8:51db:5900::9ff8]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43fb18aecbdsm45162611cf.61.2024.05.28.11.56.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 May 2024 11:56:11 -0700 (PDT) Message-ID: <72e08498-033e-4492-b6d2-f1687bb34b22@redhat.com> Date: Tue, 28 May 2024 14:56:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [COMMITTED] Strlen pass should set current range query. To: Richard Biener Cc: gcc-patches , "hernandez, aldy" References: <75656f1e-4e82-4987-aea1-d0c5602f094c@redhat.com> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Thanks. Committed with the change to the testcase. Bootstraps on x86_64-pc-linux-gnu with no regressions. Andrew On 5/28/24 02:49, Richard Biener wrote: > On Tue, May 28, 2024 at 1:24 AM Andrew MacLeod wrote: >> The strlen pass currently has a local ranger instance, but when it >> invokes SCEV or any other shared component, SCEV will not be able to >> access to this ranger as it uses get_range_query(). They will be stuck >> with global ranges. >> >> Enable/disable ranger should be used instead of a local version which >> allows other components to use the current range_query. >> >> Bootstraps on 86_64-pc-linux-gnu, but there is one regression. The >> regression is from gcc.dg/Wstringop-overflow-10.c. the function in >> question: >> >> void >> baz (char *a) >> { >> char b[16] = "abcdefg"; >> __builtin_strncpy (a, b, __builtin_strnlen (b, 7)); /* { dg-bogus >> "specified bound depends on the length of the source argument" } */ >> } >> >> when compiled with -O2 -Wstringop-overflow -Wstringop-truncation >> >> it now spits out: >> >> b2.c: In function ‘baz’: >> b2.c:24:3: warning: ‘__builtin_strncpy’ output 2 truncated before >> terminating nul copying bytes from a string of the same length >> [-Wstringop-truncation] >> 24 | __builtin_strncpy (a, b, __builtin_strnlen (b, 7)); /* { >> dg-bogus "specified bound depends on the length of the source argument" } */ >> >> It seems like maybe something got smarter by setting the current range >> query and this is a legitimate warning for this line of code? There >> will indeed not be a NULL copied as there are 7 characters in the string... >> >> Is this a testcase issue where this warning should have been issued >> before, or am I misunderstanding the warning? > I think the warning makes sense in this case. But I'm not sure why the > dg-bogus is there, that looks like a valid complaint as well?! > > I think the patch is OK. > > Richard. > >> Andrew >> >> PS im afraid of adjusting the status quo in this pass... :-P Not >> allowing sSCEV to access the current ranger is causing me other issues >> with the fix for 115221. This *should* have been a harmless change >> sigh. :-( The whole mechanism should just use the current range-query >> instad of passing a ranger pointer aorund. But that a much bigger >> issue. one thing at a time. >> >> >> From c43236cb59e11cadda2654edc117d9270dff75c6 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 27 May 2024 13:20:13 -0400 Subject: [PATCH 1/5] Strlen pass should set current range query. The strlen pass currently has a local ranger instance, but when it invokes SCEV, scev will not be able to access to this ranger. Enable/disable ranger shoud be used, allowing other components to use the current range_query. gcc/ * tree-ssa-strlen.cc (strlen_pass::strlen_pass): Add function pointer and initialize ptr_qry with current range_query. (strlen_pass::m_ranger): Remove. (printf_strlen_execute): Enable and disable ranger. gcc/testsuite/ * gcc.dg/Wstringop-overflow-10.c: Add truncating warning. --- gcc/testsuite/gcc.dg/Wstringop-overflow-10.c | 2 +- gcc/tree-ssa-strlen.cc | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-10.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-10.c index bace08ad5d3..ddc27fc0580 100644 --- a/gcc/testsuite/gcc.dg/Wstringop-overflow-10.c +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-10.c @@ -21,7 +21,7 @@ void baz (char *a) { char b[16] = "abcdefg"; - __builtin_strncpy (a, b, __builtin_strnlen (b, 7)); /* { dg-bogus "specified bound depends on the length of the source argument" } */ + __builtin_strncpy (a, b, __builtin_strnlen (b, 7)); /* { dg-warning "output truncated before terminating nul" } */ } void fill (char *); diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index 7596dd80942..c43a2da2836 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -235,9 +235,9 @@ get_range (tree val, gimple *stmt, wide_int minmax[2], class strlen_pass : public dom_walker { public: - strlen_pass (cdi_direction direction) + strlen_pass (function *fun, cdi_direction direction) : dom_walker (direction), - ptr_qry (&m_ranger), + ptr_qry (get_range_query (fun)), m_cleanup_cfg (false) { } @@ -299,8 +299,6 @@ public: unsigned HOST_WIDE_INT lenrng[2], unsigned HOST_WIDE_INT *size, bool *nulterm); - gimple_ranger m_ranger; - /* A pointer_query object to store information about pointers and their targets in. */ pointer_query ptr_qry; @@ -5912,9 +5910,10 @@ printf_strlen_execute (function *fun, bool warn_only) ssa_ver_to_stridx.safe_grow_cleared (num_ssa_names, true); max_stridx = 1; + enable_ranger (fun); /* String length optimization is implemented as a walk of the dominator tree and a forward walk of statements within each block. */ - strlen_pass walker (CDI_DOMINATORS); + strlen_pass walker (fun, CDI_DOMINATORS); walker.walk (ENTRY_BLOCK_PTR_FOR_FN (fun)); if (dump_file && (dump_flags & TDF_DETAILS)) @@ -5939,6 +5938,7 @@ printf_strlen_execute (function *fun, bool warn_only) strlen_to_stridx = NULL; } + disable_ranger (fun); scev_finalize (); loop_optimizer_finalize (); -- 2.41.0