From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 10F2A3857B87 for ; Fri, 29 Jul 2022 08:05:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10F2A3857B87 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-K5ItFsjkMZywiic_5V2rHw-1; Fri, 29 Jul 2022 04:05:01 -0400 X-MC-Unique: K5ItFsjkMZywiic_5V2rHw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E96A3801161; Fri, 29 Jul 2022 08:05:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 035EF1121314; Fri, 29 Jul 2022 08:05:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 26T84wqN234423 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 29 Jul 2022 10:04:58 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 26T84vRF234422; Fri, 29 Jul 2022 10:04:57 +0200 Date: Fri, 29 Jul 2022 10:04:57 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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-List-Received-Date: Fri, 29 Jul 2022 08:05:06 -0000 Hi! The allowed syntaxes of atomic compare don't allow ()s around the condition of ?:, but we were accepting it in one case for C++. Fixed thusly. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2022-07-29 Jakub Jelinek PR c++/106448 * parser.cc (cp_parser_omp_atomic): For simple cast followed by CPP_QUERY token, don't try cp_parser_binary_operation if compare is true. * c-c++-common/gomp/atomic-32.c: New test. --- gcc/cp/parser.cc.jj 2022-07-26 10:32:23.557273390 +0200 +++ gcc/cp/parser.cc 2022-07-28 15:12:44.288195066 +0200 @@ -41535,7 +41535,9 @@ restart: goto saw_error; } token = cp_lexer_peek_token (parser->lexer); - if (token->type != CPP_SEMICOLON && !cp_tree_equal (lhs, rhs1)) + if (token->type != CPP_SEMICOLON + && (!compare || token->type != CPP_QUERY) + && !cp_tree_equal (lhs, rhs1)) { cp_parser_abort_tentative_parse (parser); cp_parser_parse_tentatively (parser); --- gcc/testsuite/c-c++-common/gomp/atomic-32.c.jj 2022-07-28 15:23:54.567237524 +0200 +++ gcc/testsuite/c-c++-common/gomp/atomic-32.c 2022-07-28 15:25:25.127027325 +0200 @@ -0,0 +1,14 @@ +/* PR c++/106448 */ + +int x, expr; + +void +foo (void) +{ + #pragma omp atomic compare + x = (expr > x) ? expr : x; /* { dg-error "invalid (form|operator)" } */ + #pragma omp atomic compare + x = (x < expr) ? expr : x; /* { dg-error "invalid (form|operator)" } */ + #pragma omp atomic compare + x = (x == expr) ? expr : x; /* { dg-error "invalid (form|operator)" } */ +} Jakub