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;

  <bb 2> [local count: 178992760]:
  MEM <uint128_t> [(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?

Thanks
Dave

Reply via email to