From patchwork Sat Nov 20 08:39:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 47964 X-Patchwork-Delegate: thomas@schwinge.name 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 0F0F83858422 for ; Sat, 20 Nov 2021 08:40:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F0F83858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637397632; bh=BSZVGazstvY2q7OjEQRXch4Y6OspoZAP/JKlRjR0PbA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yIMns5KZzxaYdDB9KCuoOjHfqWtPaZ1wV3aKVSlPCJ//EyGskYeqdRUJbYZO71kVj TkSAN+pToE4+y4RFlDwjgM55rQT4dq8nBZnassYKhNczouAHWp979TthvUQlDwaqrk 7SW79/mBlEjx0tk+ZhviDF8XIJQW1OCvAULQiBrY= 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 9B1E83858D3C for ; Sat, 20 Nov 2021 08:40:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B1E83858D3C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-0RyhB2uwMTezeyIzUF1Gfw-1; Sat, 20 Nov 2021 03:39:59 -0500 X-MC-Unique: 0RyhB2uwMTezeyIzUF1Gfw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EC2F8799E0; Sat, 20 Nov 2021 08:39:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEC905D9DE; Sat, 20 Nov 2021 08:39:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1AK8ds5A2606376 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 20 Nov 2021 09:39:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AK8dr0V2606375; Sat, 20 Nov 2021 09:39:53 +0100 Date: Sat, 20 Nov 2021 09:39:53 +0100 To: Thomas Schwinge Subject: [PATCH] openacc: Fix up C++ #pragma acc routine handling [PR101731] Message-ID: <20211120083953.GZ2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: Tobias Burnus , gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs because two function declarations are nested in each other and the acc routine handling code isn't prepared to put the pragma on both. The fix is similar to what #pragma omp declare {simd,variant} does, in particular set the fndecl_seen flag already in cp_parser_late_parsing* when we encounter it rather than only after we finalize it. In cp_finalize_oacc_routine I had to move the fndecl_seen diagnostics to non-FUNCTION_DECL block, because for FUNCTION_DECLs the flag is already known to be set from cp_parser_late_parsing_oacc_routine, but can't be removed altogether, because that regresses quality of 2 goacc/routine-5.c diagnostics - we drop "a single " from the '#pragma acc routine' not immediately followed by a single function declaration or definition diagnostic say on #pragma acc routine int foo (), b; if we drop it altogether. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-11-20 Jakub Jelinek PR c++/101731 * parser.c (cp_parser_late_parsing_oacc_routine): Set parser->oacc_routine->fndecl_seen here, rather than ... (cp_finalize_oacc_routine): ... here. Don't error if parser->oacc_routine->fndecl_seen is set for FUNCTION_DECLs. * c-c++-common/goacc/routine-6.c: New test. Jakub --- gcc/cp/parser.c.jj 2021-11-19 16:39:51.534595887 +0100 +++ gcc/cp/parser.c 2021-11-19 22:14:41.209591009 +0100 @@ -46852,8 +46852,8 @@ cp_parser_late_parsing_oacc_routine (cp_ emission easier. */ parser->oacc_routine->clauses = nreverse (parser->oacc_routine->clauses); cp_parser_pop_lexer (parser); - /* Later, cp_finalize_oacc_routine will process the clauses, and then set - fndecl_seen. */ + /* Later, cp_finalize_oacc_routine will process the clauses. */ + parser->oacc_routine->fndecl_seen = true; return attrs; } @@ -46871,16 +46871,17 @@ cp_finalize_oacc_routine (cp_parser *par || fndecl == error_mark_node) return; - if (parser->oacc_routine->fndecl_seen) - { - error_at (parser->oacc_routine->loc, - "%<#pragma acc routine%> not immediately followed by" - " a single function declaration or definition"); - parser->oacc_routine = NULL; - return; - } if (TREE_CODE (fndecl) != FUNCTION_DECL) { + if (parser->oacc_routine->fndecl_seen) + { + error_at (parser->oacc_routine->loc, + "%<#pragma acc routine%> not immediately followed by" + " a single function declaration or definition"); + parser->oacc_routine = NULL; + return; + } + cp_ensure_no_oacc_routine (parser); return; } @@ -46921,11 +46922,6 @@ cp_finalize_oacc_routine (cp_parser *par parser->oacc_routine->clauses, DECL_ATTRIBUTES (fndecl)); } - - /* Don't unset parser->oacc_routine here: we may still need it to - diagnose wrong usage. But, remember that we've used this "#pragma acc - routine". */ - parser->oacc_routine->fndecl_seen = true; } } --- gcc/testsuite/c-c++-common/goacc/routine-6.c.jj 2021-11-19 22:13:11.150864445 +0100 +++ gcc/testsuite/c-c++-common/goacc/routine-6.c 2021-11-19 22:13:11.150864445 +0100 @@ -0,0 +1,4 @@ +/* PR c++/101731 */ + +#pragma acc routine /* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */ +int foo (int bar ());