Following thread from Thomas Breuel, http://gcc.gnu.org/ml/fortran/2008-11/msg00044.html
program test integer, parameter :: n = 100 real, pointer :: a(:),temp(:) ! pointer or allocatable have the same effect allocate(a(n), temp(n)) temp(1:size(a)) = a end program produces test () { struct array01_real(kind=4) a; struct array01_real(kind=4) temp; static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 1}; a.data = 0B; temp.data = 0B; _gfortran_set_options (8, (void *) &options.0); { void * D.646; a.dtype = 281; a.dim[0].lbound = 1; a.dim[0].ubound = 100; a.dim[0].stride = 1; D.646 = __builtin_malloc (400); if (D.646 == 0B) { _gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1}); } a.data = D.646; a.offset = -1; } { void * D.647; temp.dtype = 281; temp.dim[0].lbound = 1; temp.dim[0].ubound = 100; temp.dim[0].stride = 1; D.647 = __builtin_malloc (400); if (D.647 == 0B) { _gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1}); } temp.data = D.647; temp.offset = -1; } { integer(kind=4) D.664; void * D.662; void * D.661; integer(kind=4) D.660; integer(kind=4) D.659; logical(kind=4) D.658; struct array01_real(kind=4) atmp.1; struct array01_real(kind=4) * D.656; integer(kind=4) D.655; struct array01_real(kind=4) * D.654; integer(kind=4) D.653; real(kind=4)[0:] * D.652; integer(kind=4) D.651; integer(kind=4) D.650; integer(kind=4) D.649; real(kind=4)[0:] * D.648; D.648 = (real(kind=4)[0:] *) a.data; D.649 = a.offset; D.650 = a.dim[0].lbound; D.651 = a.dim[0].ubound; D.652 = (real(kind=4)[0:] *) temp.data; D.653 = temp.offset; D.654 = &a; D.655 = _gfortran_size0 (D.654); D.656 = &a; atmp.1.dtype = 281; atmp.1.dim[0].stride = 1; atmp.1.dim[0].lbound = 0; atmp.1.dim[0].ubound = _gfortran_size0 (D.656) + -1; D.658 = _gfortran_size0 (D.656) <= 0; D.659 = _gfortran_size0 (D.656); D.660 = D.658 ? 0 : D.659 * 4; if (D.660 < 0) { _gfortran_runtime_error (&"Attempt to allocate a negative amount of memo ry."[1]{lb: 1 sz: 1}); } D.661 = __builtin_malloc (MAX_EXPR <D.660, 1>); if (D.661 == 0B) { _gfortran_os_error (&"Memory allocation failed"[1]{lb: 1 sz: 1}); } D.662 = D.661; atmp.1.data = D.662; atmp.1.offset = 0; D.664 = NON_LVALUE_EXPR <D.650>; { integer(kind=4) D.667; integer(kind=4) D.666; integer(kind=4) S.2; D.666 = a.dim[0].stride; D.667 = temp.dim[0].stride; S.2 = 0; while (1) { if (_gfortran_size0 (D.656) + -1 < S.2) goto L.1; (*(real(kind=4)[0:] *) atmp.1.data)[S.2] = (*D.648)[(S.2 + D.664) * D. 666 + D.649]; S.2 = S.2 + 1; } L.1:; S.2 = 0; while (1) { if (_gfortran_size0 (D.656) + -1 < S.2) goto L.2; (*D.652)[(S.2 + 1) * D.667 + D.653] = (*(real(kind=4)[0:] *) atmp.1.da ta)[S.2]; S.2 = S.2 + 1; } L.2:; } { void * D.663; D.663 = atmp.1.data; if (D.663 != 0B) { __builtin_free (D.663); } } } } Calls to gfortran_size0 are appearing withing the scalarized loop because the expression for the upper bound of atmp is not stabilized. -- Summary: Bounds of a pointer/allocatable array not stabilized Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: wrong-code, missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: pault at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033