Dear Tobias, Nit pick: I find that '(\\(integer\\(kind=8\\)\\) )?' is easier to parse than '(\\(integer\\(kind=8\\)\\) |)' (a matter of taste and I won't argue about it).
> > /opt/gcc/work/gcc/testsuite/gfortran.dg/class_48.f90: In function > > '__final_test2_T.2138.constprop.0': > > /opt/gcc/work/gcc/testsuite/gfortran.dg/class_48.f90:39:0: warning: > > iteration 2147483648 invokes undefined behavior > > [-Waggressive-loop-optimizations] > > class(t), allocatable :: a > ^ > > I have not fully understood why this happens. It seems to have something > to do with cloning/const propagation. Looking at the original dump, the > optimized dump at -O0, -O2 and -O3 - and at the FE code -, I believe the > generated code is correct. > > The cloning propagates the rank == 1 into the cloned finalizer, which > permits to drastically simplify the scalarizer. That allows to remove > one loop (the one which is warned about?) and to simplify another loop > into a single trip. > > Thus, my working hypothesis is that either the warning is wrong or that > something goes wrong with the loop optimization, triggering the warning. >From the above, I am not sure if you see the warning. Do you see it? If yes, what are you planning? If I comment the lines allocate (two%a) ! one = two ! if (.not.allocated (one%a)) call abort () ! if (allocated (one%a%x)) call abort () allocate (two%a%x(2)) two%a%x(:) = 7890 ! one = two ! if (any (one%a%x /= 7890)) call abort () the test compiles without warning and runs without failure while compiling the following reduced test subroutine test2 () type t integer, allocatable :: x(:) end type t type t2 class(t), allocatable :: a end type t2 type(t2) :: one, two allocate (two%a) one = two end subroutine test2 call test2 () end gives the warning. If I grep for 'final' in class_48_red.f90.165t.optimized I see ;; Function __final_test2_T (__final_test2_T.1908, funcdef_no=1, decl_uid=1908, symbol_order=0) __final_test2_T (struct array7_t & restrict array, integer(kind=8) byte_stride, logical(kind=1) fini_coarray) static struct __vtype_test2_T __vtab_test2_T = {._hash=84164405, ._size=48, ._extends=0B, ._def_init=&__def_init_test2_T, ._copy=__copy_test2_T, ._final=__final_test2_T}; __final_test2_T (&desc.7, _25, 1); __final_test2_T (&desc.8, _25, 1); with -O2 and -m64, but ;; Function __final_test2_T.1854.constprop.0 (__final_test2_T.1854.constprop.0, funcdef_no=5, decl_uid=2159, symbol_order=16) __final_test2_T.1854.constprop.0 (struct array7_t & restrict array, integer(kind=4) byte_stride, logical(kind=1) fini_coarray) __final_test2_T.1854.constprop.0 (&desc.7, 24, 1); __final_test2_T.1854.constprop.0 (&desc.8, 24, 1); with -O2 and -m32. With -O3 the last two lines of the above are no longer present with -m64, while there is no final with -m32. Dominique