From patchwork Tue Mar 8 14:25:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1603046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCd0b4MHJz9s5P for ; Wed, 9 Mar 2022 01:25:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B4953853809 for ; Tue, 8 Mar 2022 14:25:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id D96193858C83; Tue, 8 Mar 2022 14:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D96193858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,165,1643702400"; d="diff'?scan'208";a="72885785" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 08 Mar 2022 06:25:14 -0800 IronPort-SDR: E1f7+LOEUkyRzcNK+BqE7SgG2hLy0oNeCkJsmg+pLByL4ApX1z2Wr8q6UUyZaY+YPugrkmfSAT x8uD7GnADaiwjhW80wehJqlABsTHuNTswa/wbZLek3CX+Z7vHy2HGOODFr6KKdFMXwyI0LLNLy htIByJKMICmUg9ghfFLrZmyAtqxC4ihRKwB7b24ygU5rRwEKuENceo+houtsiYD/Od9/5ejFe+ vbEYdZxBr5EiWtLdQLPy9qlgMePyqkn2rb+FWU1/evmQrqTCaxV2CRvpkx/xLJaEGMBUwwZ50+ PuM= Message-ID: Date: Tue, 8 Mar 2022 15:25:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Content-Language: en-US To: gcc-patches , fortran , Thomas Schwinge , Jakub Jelinek From: Tobias Burnus Subject: [Patch] Fortran: OpenMP/OpenACC avoid uninit access in size calc for mapping X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi Thomas & Jakub, found when working on the deep-mapping patch* with OpenMP code (and part of that patch) but it already shows up in an existing OpenACC testcase. I think it makes sense to fix it already for GCC 12. Problem: Also for unallocated allocatables, their size was calculated - the 'if(desc.data == NULL)' check was only added for pointers. Result after the patch: When compiling with -O (which is the default for goacc.exp), the warning now disappears. Thus, I now use '-O0' and the previous "is uninitialized" is now "may be uninitialized". Unrelated to the patch and the testcase, I added some 'allocate'**/'if(allocated())' to the testcase - as otherwise uninit vars would be accessed. (Not relevant for the warning or the patch - but I prefer no invalid code in testcases, if it can be avoided.) OK for mainline? Tobias * https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591144.html ** I am actually not sure whether 'acc update(b)' will/should map a previous allocated variable - or whether it should. But that's unrelated to this bug fix. See also: https://gcc.gnu.org/PR96668 for the re-mapping in OpenMP (works for arrays but not scalars). ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: OpenMP/OpenACC avoid uninit access in size calc for mapping gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses, gfc_omp_finish_clause): Obtain size for mapping only if allocatable array is allocated. gcc/testsuite/ChangeLog: * gfortran.dg/goacc/array-with-dt-1.f90: Run with -O0 and update dg-warning. * gfortran.dg/goacc/pr93464.f90: Likewise. gcc/fortran/trans-openmp.cc | 6 ++++-- gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 | 12 +++++++++--- gcc/testsuite/gfortran.dg/goacc/pr93464.f90 | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 4d56a771349..fad76a4791f 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -1597,7 +1597,8 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) tree size = create_tmp_var (gfc_array_index_type); tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type)); elemsz = fold_convert (gfc_array_index_type, elemsz); - if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER + if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE + || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT) { stmtblock_t cond_block; @@ -3208,7 +3209,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, /* We have to check for n->sym->attr.dimension because of scalar coarrays. */ - if (n->sym->attr.pointer && n->sym->attr.dimension) + if ((n->sym->attr.pointer || n->sym->attr.allocatable) + && n->sym->attr.dimension) { stmtblock_t cond_block; tree size diff --git a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 index 136e42acd59..f6880238c89 100644 --- a/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/array-with-dt-1.f90 @@ -1,4 +1,4 @@ -! { dg-additional-options -Wuninitialized } +! { dg-additional-options "-Wuninitialized -O0" } type t integer, allocatable :: A(:,:) @@ -8,9 +8,15 @@ type(t), allocatable :: b(:) ! { dg-note {'b' declared here} {} { target *-*-* } .-1 } !$acc update host(b) -! { dg-warning {'b\.dim\[0\]\.ubound' is used uninitialized} {} { target *-*-* } .-1 } -! { dg-warning {'b\.dim\[0\]\.lbound' is used uninitialized} {} { target *-*-* } .-2 } +! { dg-warning {'b\.dim\[0\]\.ubound' may be used uninitialized} {} { target *-*-* } .-1 } +! { dg-warning {'b\.dim\[0\]\.lbound' may be used uninitialized} {} { target *-*-* } .-2 } + +allocate(b(1)) +!$acc update host(b) !$acc update host(b(:)) + +!$acc update host(b(1)%A) +allocate(b(1)%A(1,1)) !$acc update host(b(1)%A) !$acc update host(b(1)%A(:,:)) end diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 index c92f1d3d8b2..18531abdf77 100644 --- a/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/pr93464.f90 @@ -2,17 +2,17 @@ ! ! Contributed by G. Steinmetz -! { dg-additional-options -Wuninitialized } +! { dg-additional-options "-Wuninitialized -O0" } program p character :: c(2) = 'a' character, allocatable :: z(:) ! { dg-note {'z' declared here} {} { target *-*-* } .-1 } !$acc parallel - ! { dg-warning {'z\.dim\[0\]\.ubound' is used uninitialized} {} { target *-*-* } .-1 } - ! { dg-warning {'z\.dim\[0\]\.lbound' is used uninitialized} {} { target *-*-* } .-2 } + ! { dg-warning {'z\.dim\[0\]\.ubound' may be used uninitialized} {} { target *-*-* } .-1 } + ! { dg-warning {'z\.dim\[0\]\.lbound' may be used uninitialized} {} { target *-*-* } .-2 } !$omp target - z = c + if (allocated(z)) z = c !$acc end parallel !$omp end target print *, z