From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id C4A8E3858412 for ; Mon, 24 Oct 2022 20:33:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4A8E3858412 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.95,210,1661846400"; d="scan'208";a="85167319" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 24 Oct 2022 12:33:44 -0800 IronPort-SDR: /rdWNdT5GOwRm7kHquNNgg3WJ29DwDzdV22hL+2QdY4ZlROkEYHfJvrutNJY/YcHRiGW4G9cXY KL08HuESM5b9aWU/gd9DD+QLIEXGSQWq8k8S4qSgtZ9lt9YKX8b+OLBivWitCM02RTMHomfot6 Zmz+KsZ00O4F9XsLz0B8kVrjVooogHmX+EUFRYGm3hcIUxPGtL3mWr8v6tV3U+N8j+1Ma/HtEx JtWIZCR8fwA2l3l/GDAJQ3aktCTdJhL/uIcoce1Fz/m04gBqvXHUzDqgTRho1I8ffN9QN41NLG gm4= From: Thomas Schwinge To: , Tobias Burnus , "Jakub Jelinek" Subject: OpenACC 'acc_is_present' on un-allocated array: '-Wuninitialized' diagnostics User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Mon, 24 Oct 2022 22:33:36 +0200 Message-ID: <87h6ztneqn.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! Given the following reduced code, from a bigger test case that I'm currently writing: program main use openacc implicit none integer, allocatable :: ar(:,:,:) logical :: l if (allocated (ar)) stop 10 ! just for illustration l =3D acc_is_present (ar) print *, l end program main ..., this results in a list of '-Wuninitialized' diagnostics (have not checked if also bad/"unexpected" code gnerated), and from the '*.original' dump it's clear where that's coming from: __attribute__((fn spec (". "))) void MAIN__ () { struct array03_integer(kind=3D4) ar; logical(kind=3D4) l; ar.data =3D 0B; ar.dtype =3D {.elem_len=3D4, .rank=3D3, .type=3D1}; if ((integer(kind=3D4)[0:] * restrict) ar.data !=3D 0B) { _gfortran_stop_numeric (10, 0); } L.1:; { integer(kind=3D8) D.4260; integer(kind=3D8) D.4261; integer(kind=3D8) D.4262; integer(kind=3D8) D.4263; integer(kind=3D8) D.4264; integer(kind=3D8) D.4265; struct array03_integer(kind=3D4) parm.0; integer(kind=3D8) D.4272; integer(kind=3D8) D.4273; D.4260 =3D ar.dim[0].lbound; D.4261 =3D ar.dim[0].ubound; D.4262 =3D ar.dim[1].lbound; D.4263 =3D ar.dim[1].ubound; D.4264 =3D ar.dim[2].lbound; D.4265 =3D ar.dim[2].ubound; parm.0.span =3D 4; parm.0.dtype =3D {.elem_len=3D4, .rank=3D3, .type=3D1}; parm.0.dim[0].lbound =3D 1; parm.0.dim[0].ubound =3D (1 - D.4260) + D.4261; parm.0.dim[0].stride =3D 1; D.4272 =3D ar.dim[1].stride; parm.0.dim[1].lbound =3D 1; parm.0.dim[1].ubound =3D (1 - D.4262) + D.4263; parm.0.dim[1].stride =3D NON_LVALUE_EXPR ; D.4273 =3D ar.dim[2].stride; parm.0.dim[2].lbound =3D 1; parm.0.dim[2].ubound =3D (1 - D.4264) + D.4265; parm.0.dim[2].stride =3D NON_LVALUE_EXPR ; parm.0.data =3D (void *) &(*(integer(kind=3D4)[0:] * restrict) ar.d= ata)[((D.4260 - ar.dim[0].lbound) + (D.4262 - ar.dim[1].lbound) * D.4272) += (D.4264 - ar.dim[2].lbound) * D.4273]; parm.0.offset =3D ~NON_LVALUE_EXPR - NON_LVALUE_EXPR ; l =3D acc_is_present_array_h (&parm.0); } [...] Note 'D.4260 =3D ar.dim[0].lbound;', etc., with these 'ar' fields not having been initialized. For reference, OpenACC 'acc_is_present' is implemented in 'libgomp/openacc.f90': [...] 72 module openacc_internal 73 use openacc_kinds 74 implicit none 75 76 interface [...] 360 function acc_is_present_array_h (a) 361 logical acc_is_present_array_h 362 type (*), dimension (..), contiguous :: a 363 end function [...] 508 end interface 509 510 interface [...] 698 function acc_is_present_l (a, len) & 699 bind (C, name =3D "acc_is_present") 700 use iso_c_binding, only: c_int32_t, c_size_t 701 !GCC$ ATTRIBUTES NO_ARG_CHECK :: a 702 integer (c_int32_t) :: acc_is_present_l 703 type (*), dimension (*) :: a 704 integer (c_size_t), value :: len 705 end function [...] 760 end interface 761 end module openacc_internal 762 763 module openacc 764 use openacc_kinds 765 use openacc_internal 766 implicit none 767 768 private [...] 793 public :: [...], acc_is_present [...] 961 interface acc_is_present 962 procedure :: acc_is_present_32_h 963 procedure :: acc_is_present_64_h 964 procedure :: acc_is_present_array_h 965 end interface [...] 1006 end module openacc [...] 1413 function acc_is_present_array_h (a) 1414 use openacc_internal, only: acc_is_present_l 1415 logical acc_is_present_array_h 1416 type (*), dimension (..), contiguous :: a 1417 acc_is_present_array_h =3D acc_is_present_l (a, sizeof (a)) /=3D = 0 1418 end function [...] GCC currently implements OpenACC 2.6, , which in 3.2.30. "acc_is_present" states: *Summary* The 'acc_is_present' routine tests whether a host variable or= array region is present on the device. *Format* C or C++: int acc_is_present( h_void*, size_t ); Fortran: logical function acc_is_present( a ) logical function acc_is_present( a, len ) type(*), dimension(..) :: a integer :: len *Description* The 'acc_is_present' routine tests whether the specified = host data is present on the device. In C, the arguments are a pointer to the data and length= in bytes; the function returns nonzero if the specified data is fully present, and zero otherw= ise. In Fortran, two forms are supported. In the first, the argument is a contiguous array section of = intrinsic type. In the second, the first argument is a variable or array element and the second is the= length in bytes. The function returns '.true.' if the specified data is fully present, and '.false.' = otherwise. If the byte length is zero, the function returns nonzero in C or '.true.' in Fortran if the g= iven address is present at all on the device. I may certainly be wrong on that -- still not too much of a Fortran programmer... ;'-| -- but just like an "inquiry function" 'if (allocated (ar))', I would have expected 'acc_is_present (ar)' to also work fine on un-allocated data (act as if called with a C/C++ 'NULL' pointer). Well, and maybe that's even what's happening, but there's the 'len' calculation that's firing here. Should that one simply be put into 'if (ar.data !=3D NULL)', and 'else' calculate a length of zero? So, is the problem (a) in the user code, (b) in the GCC implementation -- and/or (c) in the OpenACC specification even? Gr=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955