From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id 56F9A3858290 for ; Wed, 12 Oct 2022 18:32:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56F9A3858290 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1oigXI-0007zA-PD for fortran@gcc.gnu.org; Wed, 12 Oct 2022 20:32:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: fortran@gcc.gnu.org From: Harald Anlauf Subject: Re: Question about Fortran bounds and -Wanalyzer-use-of-uninitialized-value Date: Wed, 12 Oct 2022 20:32:50 +0200 Message-ID: References: <575b023befd11f896b1f1816b757e4f55cb0b0a3.camel@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US In-Reply-To: <575b023befd11f896b1f1816b757e4f55cb0b0a3.camel@redhat.com> X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,SPF_HELO_NONE,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 Dave, Am 12.10.22 um 15:46 schrieb David Malcolm via Fortran: > Sorry in advance if this is a silly question; my knowledge of Fortran > is next to nothing, I'm afraid. > > PR analyzer/107210 reports an ICE in -fanalyzer on this reproducer: > > > ! { dg-additional-options "-O1" } > > subroutine check_int (j) > INTEGER(4) :: i, ia(5), ib(5,4), ip, ipa(:) > target :: ib > POINTER :: ip, ipa > logical :: l(5) > > l = (/ sizeof(i) == 4, sizeof(ia) == 20, sizeof(ib) == 80, & > sizeof(ip) == 4, sizeof(ipa) == 8 /) ! { dg-warning "use of uninitialized value" } > > if (any(.not.l)) STOP 4 > > end subroutine check_int > > > The fix for the ICE is trivial (a missing check that tree_fits_uhwi_p), > but after the fix, I see these warnings from the analyzer: > > > 10 | sizeof(ip) == 4, sizeof(ipa) == 8 /) > | ^ > Warning: use of uninitialized value ‘ipa.dim[0].ubound’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] > ‘check_int’: events 1-3 > | > | 4 | INTEGER(4) :: i, ia(5), ib(5,4), ip, ipa(:) > | | ^ > | | | > | | (1) region created on stack here > | | (2) capacity: 8 bytes > |...... > | 10 | sizeof(ip) == 4, sizeof(ipa) == 8 /) > | | ~ > | | | > | | (3) use of uninitialized value ‘ipa.dim[0].ubound’ here > | > ../../src/gcc/testsuite/gfortran.dg/analyzer/pr107210.f90:10:43: > > 10 | sizeof(ip) == 4, sizeof(ipa) == 8 /) > | ^ > Warning: use of uninitialized value ‘ipa.dim[0].lbound’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] > ‘check_int’: events 1-3 > | > | 4 | INTEGER(4) :: i, ia(5), ib(5,4), ip, ipa(:) > | | ^ > | | | > | | (1) region created on stack here > | | (2) capacity: 8 bytes > |...... > | 10 | sizeof(ip) == 4, sizeof(ipa) == 8 /) > | | ~ > | | | > | | (3) use of uninitialized value ‘ipa.dim[0].lbound’ here > | > > > The gimple in question is: > > __attribute__((fn spec (". w "))) > void check_int (integer(kind=4) & restrict j) > { > integer(kind=8) ipa$dim$0$lbound; > integer(kind=8) ipa$dim$0$ubound; > logical(kind=4) A.1[5]; > logical(kind=4) l[5]; > integer(kind=8) _1; > logical(kind=4) _3; > logical(kind=4) _4; > integer(kind=8) _5; > logical(kind=4) _6; > integer(kind=8) S.5_7; > logical(kind=4) test.6_8; > integer(kind=8) S.7_9; > integer(kind=8) S.5_16; > integer(kind=8) S.7_18; > > [local count: 178992760]: > MEM [(c_char * {ref-all})&A.1] = 0x1000000010000000100000001; > _1 = ipa$dim$0$ubound_2(D) - ipa$dim$0$lbound_12(D); > _3 = _1 == 1; > MEM[(logical(kind=4) *)&A.1 + 16B] = _3; > > [...snip...] > > where the analyzer is complaining about this gimple statement: > _1 = ipa$dim$0$ubound_2(D) - ipa$dim$0$lbound_12(D); > where both: > ipa$dim$0$ubound_2(D) > and: > ipa$dim$0$lbound_12(D) > are considered by it to be uninitialized. > > Is the analyzer correct here, or is there an aspect of Fortan and/or > gimple that I'm missing? if you compile w/o -fanalyzer but with -O -Wall you will get warnings, too. Note that SIZEOF is an extension documented here: https://gcc.gnu.org/onlinedocs/gfortran/SIZEOF.html where is says: .. If the argument has the POINTER attribute, the number of bytes of the storage area pointed to is returned. ... which can be determined only if the arrays bounds are known. The testcase gfortran.dg/sizeof.f90 from which the above was reduced sets these bounds via ipa=>ib(2:3,1) If I restore this, then I get no related warnings for -O -Wall. > Thanks > Dave