From patchwork Fri Sep 16 12:42:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp734393wrt; Fri, 16 Sep 2022 05:43:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69J1PnZ0F4kHxMg3n7dFhdxp2rt6ibBiDjYSk+j+MDWBF/OBL2MlWXMfArZRks0Lk2cYLG X-Received: by 2002:a17:907:3f04:b0:741:4bf4:fe42 with SMTP id hq4-20020a1709073f0400b007414bf4fe42mr3556950ejc.664.1663332215787; Fri, 16 Sep 2022 05:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663332215; cv=none; d=google.com; s=arc-20160816; b=KjMftlgzTCO/OHmNk95pOIlIkaWX35uD1Qi6BScEMmEp3dvzt4+XyhWw/LlBShU+ek qNy8fIobqWZAHeUw8vUAxenzqKLJi13xpzkRaWmlmN9S+mAPJEqpSNjuioG6zb46Npqy rRTQU3SlunKj+znbOE6Ye/D0JLUxpD5Yc9URZfhYNohkmQF1hPZc6QVL8reb0jHVPkxg aEF4BjjaLaVSQElbxoVrTKTAno0xoL8XXz1pmp3s89brBXakOQl1Io0JujhEDmwuPIjT jt/eLdatYZptymu8MmUX2Sw2vgtemy7UvOH3Pr+RwdoPmpvedGTQLofsl7IJ7L8n+Jv1 ZitA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PgxZjbX44dl0xk8XE/upxsUQkbKY0iLx8+lCBPRRsSo=; b=OY0vGC2FoQ68TT8d7WPNvIgDXCG58PglqvzTXPJOhMvpxa2qH3RNvOBRXukPuMmu1T FTdxc4fHEVvOvAhCr0+mfEALm88S5An4fl8DbaxjXPCMM370J94uzUvGnHX/aP89cfWb Kz6gBpWg0I7UakwNmrKNtDkrDX0kXxuyPFDz1MNVsHpRKE041WQgvqTE8gdtNSxzukwA B7nIh2M3gKuJs1J6kju7Kgng4urHIIMTOFRODGihUc0MhSjW/Jsj1N5iw6ufnZo/rHb4 LM3cFZSAtRhY2sepcOvTwDmAzvuGHRhzCZFmTuiHcrx2Rke+Qs6kufgjQASDzsXmlTX+ rOmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AoelROl1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y20-20020a056402271400b0044792d4876asi2438896edd.291.2022.09.16.05.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 05:43:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AoelROl1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3396F3853805 for ; Fri, 16 Sep 2022 12:43:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3396F3853805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663332211; bh=PgxZjbX44dl0xk8XE/upxsUQkbKY0iLx8+lCBPRRsSo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=AoelROl1c9Q209wnsJS3W39xqGIqnGFm2KrrA5T4MrUHSjNiEWXhVnmmIOiWji2w2 A7KHFSfuoAXvD8AqjqHO7WboHJjDyoW8Dx4M0m34wj9ZZIH0Yy6d5lkinwGixd1mkc z3btSztZ1hS2sL8B1uMHc8jQ4inO5HGM8yv0sosk= 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 1BFE73821FEE for ; Fri, 16 Sep 2022 12:42:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BFE73821FEE Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-344-G73a6BHrP6K3IUU9W4f6tg-1; Fri, 16 Sep 2022 08:42:44 -0400 X-MC-Unique: G73a6BHrP6K3IUU9W4f6tg-1 Received: by mail-ed1-f72.google.com with SMTP id s17-20020a056402521100b004511c8d59e3so14633658edd.11 for ; Fri, 16 Sep 2022 05:42:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=PgxZjbX44dl0xk8XE/upxsUQkbKY0iLx8+lCBPRRsSo=; b=2pVe2Em664qA7mi0VI2k8Gysi91PM2viOTeg2Czhsrf7Coq24UuNNnfLzTxrN5Mw0b ELHgQBFfwDeLrqaFWFtQnS0EBySNNwjCBG3kIL0Yhlu23pMpC1fZBI4rWx0WqVS6xc10 7SatA7ueTxB8hi6ZHu+p0H/tVBeRKCFSGzc9PvCbM4uFqsENjEy+kSmohKk6RfrQ0Nrs aAt3iw6S9+vqe/Gv96kls43pae6LqQjcArM3YLUgGYjS3kmd8xC/KKUuffFEOzsQaBZx QQNbFuFSYwy7SizGCbLOkyx0MaMaZHOP8gkwb7vFKJQweSW65GhZqxqz+wKz3cmBLtTs /9TA== X-Gm-Message-State: ACrzQf0Pi1iGFUTZbfeEE/Q6iphou1EMSrjycTaC/EFgOm26yR/4C4x5 0CKXzCk4czRwgiBE3RptbMeoitr3hk7ifZbYjqaxwG818ZuIp7kd7ObfGf5PVeUAQ9iqBFkQibh NmKhSpnUKzmA2U0QdxSEYgaiC5lLbWw8RzL6Lgd1o/WAIZwzDgGN9mgwiFdqfu/Fkhw== X-Received: by 2002:a17:907:3d8e:b0:77b:fd55:affe with SMTP id he14-20020a1709073d8e00b0077bfd55affemr3366493ejc.498.1663332162779; Fri, 16 Sep 2022 05:42:42 -0700 (PDT) X-Received: by 2002:a17:907:3d8e:b0:77b:fd55:affe with SMTP id he14-20020a1709073d8e00b0077bfd55affemr3366480ejc.498.1663332162469; Fri, 16 Sep 2022 05:42:42 -0700 (PDT) Received: from barrymore.ms.mff.cuni.cz (vpn-konference.ms.mff.cuni.cz. [195.113.20.101]) by smtp.gmail.com with ESMTPSA id r6-20020a1709062cc600b007262a5e2204sm10397480ejr.153.2022.09.16.05.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 05:42:41 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: member fn in omp loc list [PR106858] Date: Fri, 16 Sep 2022 14:42:40 +0200 Message-Id: <20220916124240.176613-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_LOW, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Cc: jakub@redhat.com 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?1744130241035527745?= X-GMAIL-MSGID: =?utf-8?q?1744130241035527745?= this->f names a member function, which isn't an addressable lvalue. Give a helpful error instead of crashing. The first hunk makes the error range cover the whole expression. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/106858 gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_var_list_no_open): Pass the initial token location down. * semantics.cc (finish_omp_clauses): Check invalid_nonstatic_memfn_p. * typeck.cc (invalid_nonstatic_memfn_p): Handle null TREE_TYPE. gcc/testsuite/ChangeLog: * g++.dg/gomp/map-3.C: New test. --- gcc/cp/parser.cc | 7 +++---- gcc/cp/semantics.cc | 4 ++++ gcc/cp/typeck.cc | 3 ++- gcc/testsuite/g++.dg/gomp/map-3.C | 9 +++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/map-3.C base-commit: 3e8c4b925a9825fdb8c81f47b621f63108894362 diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 841ba6ed997..3cbe0d69de1 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -36938,10 +36938,9 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, cp_id_kind idk = CP_ID_KIND_NONE; cp_lexer_consume_token (parser->lexer); decl = convert_from_reference (decl); - decl - = cp_parser_postfix_dot_deref_expression (parser, ttype, - decl, false, - &idk, loc); + decl = (cp_parser_postfix_dot_deref_expression + (parser, ttype, cp_expr (decl, token->location), + false, &idk, loc)); } /* FALLTHROUGH. */ case OMP_CLAUSE_AFFINITY: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 427b1ab5ebc..86562071612 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -8119,6 +8119,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = TREE_OPERAND (t, 1); STRIP_NOPS (t); } + if (TREE_CODE (t) == COMPONENT_REF + && invalid_nonstatic_memfn_p (EXPR_LOCATION (t), t, + tf_warning_or_error)) + remove = true; indir_component_ref_p = false; if (TREE_CODE (t) == COMPONENT_REF && (TREE_CODE (TREE_OPERAND (t, 0)) == INDIRECT_REF diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 3e461d5cdcb..22d834d3a58 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -2196,7 +2196,8 @@ invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain) return false; if (is_overloaded_fn (expr) && !really_overloaded_fn (expr)) expr = get_first_fn (expr); - if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) + if (TREE_TYPE (expr) + && DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) { if (complain & tf_error) { diff --git a/gcc/testsuite/g++.dg/gomp/map-3.C b/gcc/testsuite/g++.dg/gomp/map-3.C new file mode 100644 index 00000000000..c45f8509521 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/map-3.C @@ -0,0 +1,9 @@ +// PR c++/106858 +// { dg-additional-options "-fopenmp -fsanitize=undefined" } + +class A { + void f() { + #pragma omp target map(this->f) // { dg-error "member function" } + ; + } +};