From patchwork Thu Feb 1 21:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1894202 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=Aj6pmaBb; 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 4TQsN24cgqz23gH for ; Fri, 2 Feb 2024 08:23:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 315BA385801E for ; Thu, 1 Feb 2024 21:23:44 +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 E1F863858D33 for ; Thu, 1 Feb 2024 21:23:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1F863858D33 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 E1F863858D33 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=1706822605; cv=none; b=eRqarKJZYZsRkGMlUXw4a8NBuyUzgl+yRWxuwSVvQhbIpjN+uiRI5v+bhFDILxLT3N2VchiNTrW7bJ+n2J5D5m/mi5Luyl/ArPoZrVF36MlHg+n1MWh+2BcwqDhM3UTg+PsdpVGb1sxUliGPKjrM16BwaPlB1q+DHB8u5qlS6d4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706822605; c=relaxed/simple; bh=VIcMiwon3bsZo0bBCH/OHLP+ec5YZqOWypnol0l5X5M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hufnLHEZ0AknH0spEB21A93IQHtUEb1OMhIIjlScuI8X/EJIGZIaRALdG3jW2Si5zVO1w+qc3NCfVuDB+whbOwSXUbZtzXQxDBvjnYf+U527JakZ6AosjCY/Hf+IxazJ8SEhGx+mlqtLjPB88jpaa3T7t2W9U+QZoAlEojla7TY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706822601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lQNqurVSHh3nWWiTxk9EmbBtHDlHnjbur4Sqq2pC6JE=; b=Aj6pmaBbWsglSCmRC1Y58DrSbdJXlEa6WT7nPU9cIwUQEZFGTez3xncOWpp093z5NIPSI7 kQUi9kVkYN5aiKQ6j3B+VfHdbCfBC9zDX2GjiKIcYcdLvB+tEZ8o86+jd9Se+mOhXO0dJy xyu8AStEUxZSL327T52Oc5c0AqmCaJc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-drbydxGdPIWMwcy5RnEAtA-1; Thu, 01 Feb 2024 16:23:20 -0500 X-MC-Unique: drbydxGdPIWMwcy5RnEAtA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5C59916D61 for ; Thu, 1 Feb 2024 21:23:19 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.17.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id C605E2166B31; Thu, 1 Feb 2024 21:23:19 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: -Wdangling-reference tweak to unbreak aarch64 Date: Thu, 1 Feb 2024 16:23:13 -0500 Message-ID: <20240201212313.97285-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? aarch64-unknown-linux-gnu now bootstraps. -- >8 -- My recent -Wdangling-reference change to not warn on std::span-like classes unfortunately caused a new warning: extending reference_like_class_p also opens the door to new warnings since we use reference_like_class_p for checking the return type of the function: either it must be a reference or a reference_like_class_p. We can consider even non-templates as std::span-like to get rid of the warning here. gcc/cp/ChangeLog: * call.cc (reference_like_class_p): Consider even non-templates for std::span-like classes. gcc/ChangeLog: * doc/invoke.texi: Update -Wdangling-reference documentation. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference21.C: New test. --- gcc/cp/call.cc | 8 ++-- gcc/doc/invoke.texi | 2 +- .../g++.dg/warn/Wdangling-reference21.C | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wdangling-reference21.C base-commit: 44764984cf24e27cf7756cffd197283b9c62db8b diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 42cbd0da036..1dac1470d3b 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -14082,8 +14082,8 @@ reference_like_class_p (tree ctype) return true; } - /* Avoid warning if CTYPE looks like std::span: it's a class template, - has a T* member, and a trivial destructor. For example, + /* Avoid warning if CTYPE looks like std::span: it has a T* member and + a trivial destructor. For example, template struct Span { @@ -14092,9 +14092,7 @@ reference_like_class_p (tree ctype) }; is considered std::span-like. */ - if (NON_UNION_CLASS_TYPE_P (ctype) - && CLASSTYPE_TEMPLATE_INSTANTIATION (ctype) - && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype)) + if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype)) for (tree field = next_aggregate_field (TYPE_FIELDS (ctype)); field; field = next_aggregate_field (DECL_CHAIN (field))) if (TYPE_PTR_P (TREE_TYPE (field))) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 14730c0c508..e9c691d63da 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3929,7 +3929,7 @@ struct Span @{ @}; @end smallexample -as @code{std::span}-like; that is, the class is a non-union class template +as @code{std::span}-like; that is, the class is a non-union class that has a pointer data member and a trivial destructor. This warning is enabled by @option{-Wall}. diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C new file mode 100644 index 00000000000..e1b6e3dd94c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C @@ -0,0 +1,44 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-Wdangling-reference" } +// Reduced from config/aarch64/aarch64-early-ra.cc. + +template struct array_slice { + using iterator = T *; + iterator begin(); + iterator end(); + iterator m_base; +}; + +struct allocno_group_info { }; + +char recog_data_2; +int record_constraints_op; +struct early_ra { + using operand_mask = int; + struct allocno_info { + int is_earlyclobbered; + }; + struct allocno_subgroup { + array_slice allocnos(); + allocno_group_info *group; + }; + allocno_subgroup get_allocno_subgroup(int); + void record_constraints(); +}; +void early_ra::record_constraints() { + operand_mask earlyclobber_operands, matched_operands, unmatched_operands, + matches_operands, op_mask = operand_mask(); + auto record_operand = [&](int, int) { + operand_mask overlaps; + matches_operands |= overlaps; + }; + for (int opno = 0; recog_data_2; ++opno) { + operand_mask op_mask = earlyclobber_operands |= op_mask; + if (0) + record_operand(1, 0); + } + if (op_mask || (matched_operands & unmatched_operands && 0)) + for (auto &allocno : get_allocno_subgroup(record_constraints_op).allocnos()) + allocno.is_earlyclobbered = true; +} +