From patchwork Sat Mar 2 00:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 209153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp247499dyc; Fri, 1 Mar 2024 17:00:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlZbfuvmJrWRiK0li+grph+7K6SWa8Q5ZDdxtJU1PZ38+iSyniyXo6Uxa3SiPQJPgwHf7gd0LM/uAfxKP33QjrTNuKHw== X-Google-Smtp-Source: AGHT+IHJxV24ZgrrnjUWFl0Rk23kYBGqT5vV+CaJ3rqbpdXqi/CF6MW7rnN725d1OiZGwbQwvNTo X-Received: by 2002:a05:6359:420c:b0:17a:e9db:bc10 with SMTP id kn12-20020a056359420c00b0017ae9dbbc10mr3642495rwb.20.1709341223291; Fri, 01 Mar 2024 17:00:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709341223; cv=pass; d=google.com; s=arc-20160816; b=tZxKBmzZ0QrAbKL5hnJNcXcSLehXvSOiib8OxpU+1+loC2rqUt+MvIx2wHQTKTnQND 5yQf7nboAuH3IAw3AL8L4GDh78PEM6N7MXZV1u9v3kQiHfRwqCNEO8zAuBJnEaMJeRvy frLcOAoXDWzweGYIZp6nQf+alIu7ZkTLyso6YkxSBFC6x81Ti4wKcmMK9o41LLRR2/64 JDW0b2EJuQDq3x2+aGzx6I1DU5m1tPmoydYQ7NTM7BvdWf5pZuCEyDI9MdJeQrTnfOoJ qDFVkZ9AeoL4lzCWvurd3IomYska8meGrfKGsVDupBpdyIo1jQKedm++fHnHTgDoihQy Jbcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=qQbp4cXXUtNmKyHj2GuVACDVHobJrni8S8vNqtAuSXs=; fh=2BFo3VQCimnyWTJsWe6sNdepvNrW+J/2ctoM6N7MZ0Y=; b=e09x85l0rPucT5fB8bVIBbjxJjny2KajA2mZAhkHfuVE6A4Xi4t7QczVEtW2iKXDax BM/vKr8GZQy+sBeHW2tr5EzjG+hf7zV41IiD+8Rj+HTcuJL8ECCtbrCoi/wiMO2N2wyZ TdmTdt7aoZVACBWhDm6vY8cUel5XK/SjnPKmjTpvsNExl+idG/zledXr6VkMDoQjvk8W BdspZcFSJY+uPjWS1ChmoJUOOfx/lSEITt741RlACynxvrlFt901SDUtMGxOnpqPZThK q60LzPKPy3Gyi5udJvivoYbTsvHeRZrt+zudYmYpQXddLEhntj0xn4/zm3k0X9cXdRl2 GECg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ROWRUyYN; arc=pass (i=1); 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fn7-20020ad45d67000000b0068f5ddb8036si4707967qvb.371.2024.03.01.17.00.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 17:00:23 -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=@redhat.com header.s=mimecast20190719 header.b=ROWRUyYN; arc=pass (i=1); 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE4EA385840E for ; Sat, 2 Mar 2024 01:00:22 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 1E6FE3858C74 for ; Sat, 2 Mar 2024 00:59:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E6FE3858C74 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 1E6FE3858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709341157; cv=none; b=Ct82Ps4eXLMOUUPk0f9SKDGdBzIIlgNAgz2SF2Yp24ouQ/YYo2Y6X3iOaAlP/ELlRwX6YmrSaZTZ5ohiFayk+hGCdkYwrnFwLqQc8L8mAmG7QvT/Zil5xTXQFZGpoYOxM78nk0TXpv7vVnVFobyaE7+TyXKZLFnMGYVbLpgJnVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709341157; c=relaxed/simple; bh=SrTZjS8jTv0OAICOpw/+68MzD0S7oFBBOs5gS8VGCqY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t2uxBwUTF49xQiOwCLJTciM1SQs6voBhgk6pnV+Hl3pWGai5g4jABjxodboUhAsa4dlo3xgPYFdoCM/iEY5StoyxU1uVlRsGT0UqkxOSxv1Zru+JnX/hy/fip82RG5kTwzZTk39SeP1pr+RqWB+0N9JWpewwT2An9qla8Ljw1r8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709341154; 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=qQbp4cXXUtNmKyHj2GuVACDVHobJrni8S8vNqtAuSXs=; b=ROWRUyYNeymG+GZivthCDzLAzS2OITR8K05NIYsOgvZi7CkhM1vw168gcfL2PKb/xs8VJm ohHZz+Q1u+JkzFtVleErxe6q/RGj8iqQn96u8s++toLlrC2kNd9ZtTSV3DiuY5o430QVu8 pop2UFJSv09QNrLO6wKVyVEk46q3GPE= 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-130-7uReIFXvOI6rVGmNHouwoQ-1; Fri, 01 Mar 2024 19:59:13 -0500 X-MC-Unique: 7uReIFXvOI6rVGmNHouwoQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 01BA9185A781 for ; Sat, 2 Mar 2024 00:59:13 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7362AC17; Sat, 2 Mar 2024 00:59:12 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: DECL_DECOMPOSITION_P cleanup Date: Fri, 1 Mar 2024 19:59:10 -0500 Message-ID: <20240302005910.924213-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792374182639179165 X-GMAIL-MSGID: 1792374182639179165 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for 15? -- >8 -- DECL_DECOMPOSITION_P already checks VAR_P but we repeat the check in a lot of places. gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Don't check VAR_P before DECL_DECOMPOSITION_P. * init.cc (build_aggr_init): Likewise. * parser.cc (cp_parser_range_for): Likewise. (do_range_for_auto_deduction): Likewise. (cp_convert_range_for): Likewise. (cp_convert_omp_range_for): Likewise. (cp_finish_omp_range_for): Likewise. * pt.cc (extract_locals_r): Likewise. (tsubst_omp_for_iterator): Likewise. (tsubst_decomp_names): Likewise. (tsubst_stmt): Likewise. * typeck.cc (maybe_warn_about_returning_address_of_local): Likewise. --- gcc/cp/decl.cc | 3 +-- gcc/cp/init.cc | 2 +- gcc/cp/parser.cc | 11 ++++------- gcc/cp/pt.cc | 11 +++-------- gcc/cp/typeck.cc | 3 +-- 5 files changed, 10 insertions(+), 20 deletions(-) base-commit: 574fd1f17f100c7c355ad26bc525ab5a3386bb2d diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index dbc3df24e77..13df91ce17c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -1928,8 +1928,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) inform (olddecl_loc, "previous declaration %q#D", olddecl); return error_mark_node; } - else if ((VAR_P (olddecl) && DECL_DECOMPOSITION_P (olddecl)) - || (VAR_P (newdecl) && DECL_DECOMPOSITION_P (newdecl))) + else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl)) /* A structured binding must be unique in its declarative region. */; else if (DECL_IMPLICIT_TYPEDEF_P (olddecl) || DECL_IMPLICIT_TYPEDEF_P (newdecl)) diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index d2586fad86b..bcfb4d350bc 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -1979,7 +1979,7 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) tree itype = init ? TREE_TYPE (init) : NULL_TREE; int from_array = 0; - if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp)) + if (DECL_DECOMPOSITION_P (exp)) { from_array = 1; init = mark_rvalue_use (init); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a310b9e8c07..8a6ced17c5c 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -14117,7 +14117,6 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl, /* For decomposition declaration get all of the corresponding declarations out of the way. */ if (TREE_CODE (v) == ARRAY_REF - && VAR_P (TREE_OPERAND (v, 0)) && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) { tree d = range_decl; @@ -14238,7 +14237,7 @@ do_range_for_auto_deduction (tree decl, tree range_expr, cp_decomp *decomp) iter_decl, auto_node, tf_warning_or_error, adc_variable_type); - if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + if (DECL_DECOMPOSITION_P (decl)) cp_finish_decomp (decl, decomp); } } @@ -14437,7 +14436,7 @@ cp_convert_range_for (tree statement, tree range_decl, tree range_expr, cp_finish_decl (range_decl, deref_begin, /*is_constant_init*/false, NULL_TREE, LOOKUP_ONLYCONVERTING, decomp); - if (VAR_P (range_decl) && DECL_DECOMPOSITION_P (range_decl)) + if (DECL_DECOMPOSITION_P (range_decl)) cp_finish_decomp (range_decl, decomp); warn_for_range_copy (range_decl, deref_begin); @@ -44288,7 +44287,6 @@ cp_convert_omp_range_for (tree &this_pre_body, tree &sl, { tree v = DECL_VALUE_EXPR (decl); if (TREE_CODE (v) == ARRAY_REF - && VAR_P (TREE_OPERAND (v, 0)) && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) { d = TREE_OPERAND (v, 0); @@ -44393,7 +44391,6 @@ cp_convert_omp_range_for (tree &this_pre_body, tree &sl, { tree v = DECL_VALUE_EXPR (orig_decl); if (TREE_CODE (v) == ARRAY_REF - && VAR_P (TREE_OPERAND (v, 0)) && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) { tree d = orig_decl; @@ -44471,7 +44468,7 @@ cp_finish_omp_range_for (tree orig, tree begin) tree decl = TREE_VEC_ELT (TREE_CHAIN (orig), 2); cp_decomp decomp_d, *decomp = NULL; - if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + if (DECL_DECOMPOSITION_P (decl)) { decomp = &decomp_d; decomp_d.decl = TREE_VEC_ELT (TREE_CHAIN (orig), 3); @@ -44497,7 +44494,7 @@ cp_finish_omp_range_for (tree orig, tree begin) NULL_TREE, tf_warning_or_error), /*is_constant_init*/false, NULL_TREE, LOOKUP_ONLYCONVERTING, decomp); - if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + if (DECL_DECOMPOSITION_P (decl)) cp_finish_decomp (decl, decomp); } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c4bc54a8fdb..4def9c45402 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -13303,14 +13303,12 @@ extract_locals_r (tree *tp, int *walk_subtrees, void *data_) { tree decl = DECL_EXPR_DECL (*tp); data.internal.add (decl); - if (VAR_P (decl) - && DECL_DECOMPOSITION_P (decl) + if (DECL_DECOMPOSITION_P (decl) && TREE_TYPE (decl) != error_mark_node) { gcc_assert (DECL_NAME (decl) == NULL_TREE); for (tree decl2 = DECL_CHAIN (decl); decl2 - && VAR_P (decl2) && DECL_DECOMPOSITION_P (decl2) && DECL_NAME (decl2) && TREE_TYPE (decl2) != error_mark_node; @@ -17912,7 +17910,6 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree &orig_declv, { tree v = DECL_VALUE_EXPR (decl); if (TREE_CODE (v) == ARRAY_REF - && VAR_P (TREE_OPERAND (v, 0)) && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) { cp_decomp decomp_d = { NULL_TREE, 0 }; @@ -18261,7 +18258,6 @@ tsubst_decomp_names (tree decl, tree pattern_decl, tree args, gcc_assert (DECL_NAME (decl) == NULL_TREE); for (decl2 = DECL_CHAIN (pattern_decl); decl2 - && VAR_P (decl2) && DECL_DECOMPOSITION_P (decl2) && DECL_NAME (decl2); decl2 = DECL_CHAIN (decl2)) @@ -18572,8 +18568,7 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl) && DECL_OMP_PRIVATIZED_MEMBER (decl)) break; - if (VAR_P (decl) - && DECL_DECOMPOSITION_P (decl) + if (DECL_DECOMPOSITION_P (decl) && TREE_TYPE (pattern_decl) != error_mark_node) { decomp = &decomp_d; @@ -18647,7 +18642,7 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl) expr = RECUR (RANGE_FOR_EXPR (t)); cp_decomp decomp_d, *decomp = NULL; - if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + if (DECL_DECOMPOSITION_P (decl)) { decomp = &decomp_d; decl = tsubst_decomp_names (decl, RANGE_FOR_DECL (t), args, diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index f5a0a2273be..db19af1d24c 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10647,8 +10647,7 @@ maybe_warn_about_returning_address_of_local (tree retval, location_t loc) && !(TREE_STATIC (whats_returned) || TREE_PUBLIC (whats_returned))) { - if (VAR_P (whats_returned) - && DECL_DECOMPOSITION_P (whats_returned) + if (DECL_DECOMPOSITION_P (whats_returned) && DECL_DECOMP_BASE (whats_returned) && DECL_HAS_VALUE_EXPR_P (whats_returned)) {