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.129.124]) by sourceware.org (Postfix) with ESMTPS id A0BB23858C2C for ; Thu, 3 Feb 2022 08:08:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0BB23858C2C 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-571-aODLufn4PyCe2iOZlhTcdA-1; Thu, 03 Feb 2022 03:08:46 -0500 X-MC-Unique: aODLufn4PyCe2iOZlhTcdA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F34B51091DA3; Thu, 3 Feb 2022 08:08:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7041616A51; Thu, 3 Feb 2022 08:08:44 +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 21388fE13856535 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 3 Feb 2022 09:08:42 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 21388ewP3856534; Thu, 3 Feb 2022 09:08:40 +0100 Date: Thu, 3 Feb 2022 09:08:40 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp, fortran: Improve !$omp atomic checks [PR104328] Message-ID: <20220203080840.GG2646553@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2022 08:08:51 -0000 Hi! The testcase shows some cases that weren't verified and we ICE on invalid because of that. One problem is that unlike before, we weren't checking if some expression is EXPR_VARIABLE with non-NULL symtree in the case where there was a conversion around it. The other two issues is that we check that in an IF ->block is non-NULL and then immediately dereference ->block->next->op, but on invalid code with no statements in the then clause ->block->next might be NULL. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2022-02-02 Jakub Jelinek PR fortran/104328 * openmp.cc (is_scalar_intrinsic_expr): If must_be_var && conv_ok and expr is conversion, verify it is a conversion from EXPR_VARIABLE with non-NULL symtree. Check ->block->next before dereferencing it. * gfortran.dg/gomp/atomic-27.f90: New test. --- gcc/fortran/openmp.cc.jj 2022-01-21 11:01:12.458449420 +0100 +++ gcc/fortran/openmp.cc 2022-02-02 20:20:22.020000000 +0100 @@ -7660,9 +7660,16 @@ static bool is_scalar_intrinsic_expr (gfc_expr *expr, bool must_be_var, bool conv_ok) { if (must_be_var - && (expr->expr_type != EXPR_VARIABLE || !expr->symtree) - && (!conv_ok || !is_conversion (expr, true, true))) - return false; + && (expr->expr_type != EXPR_VARIABLE || !expr->symtree)) + { + if (!conv_ok) + return false; + gfc_expr *conv = is_conversion (expr, true, true); + if (!conv) + return false; + if (conv->expr_type != EXPR_VARIABLE || !conv->symtree) + return false; + } return (expr->rank == 0 && !gfc_is_coindexed (expr) && (expr->ts.type == BT_INTEGER @@ -7705,6 +7712,7 @@ resolve_omp_atomic (gfc_code *code) if (next->op == EXEC_IF && next->block && next->block->op == EXEC_IF + && next->block->next && next->block->next->op == EXEC_ASSIGN) { comp_cond = next->block->expr1; @@ -7757,6 +7765,7 @@ resolve_omp_atomic (gfc_code *code) if (code->op == EXEC_IF && code->block && code->block->op == EXEC_IF + && code->block->next && code->block->next->op == EXEC_ASSIGN) { comp_cond = code->block->expr1; --- gcc/testsuite/gfortran.dg/gomp/atomic-27.f90.jj 2022-02-02 20:30:44.101437198 +0100 +++ gcc/testsuite/gfortran.dg/gomp/atomic-27.f90 2022-02-02 20:29:50.651217307 +0100 @@ -0,0 +1,34 @@ +! PR fortran/104328 +! { dg-do compile } + +subroutine foo + integer :: k = 1 + !$omp atomic compare + if ( k == 2 ) then ! { dg-error "unexpected !.OMP ATOMIC expression" } + end if +end +subroutine bar + real :: x = 1 + !$omp atomic compare + if ( x == 2 ) then ! { dg-error "unexpected !.OMP ATOMIC expression" } + end if +end +subroutine baz + integer :: i + !$omp atomic capture + i = 1 + i = i + 1. ! { dg-error "!.OMP ATOMIC capture-statement requires a scalar variable of intrinsic type" } +end +subroutine qux + integer :: i = 0 + !$omp atomic capture + i = i + 1.0 + i = i + 1.0 ! { dg-error "!.OMP ATOMIC capture-statement requires a scalar variable of intrinsic type" } +end +subroutine garply + logical :: k = .true. + !$omp atomic capture compare + if ( k ) then ! { dg-error "unexpected !.OMP ATOMIC expression" } + else + end if +end Jakub