https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68649
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> --- This is of course Fortran FE bug. What is the Fortran FE emitting right now is kind like invalid C (and invalid middle-end) below. It wouldn't be invalid C++, but for C++ that would be different baz functions and name mangling would differentiate those; that is not what is going on in C or in what libgfortran expects: typedef __SIZE_TYPE__ size_t; struct D { long stride, lower_bound, ubound; }; struct A { float *base_addr; size_t offset; long dtype; struct D dim[7]; }; struct A1 { float *base_addr; size_t offset; long dtype; struct D dim[1]; }; struct A2 { float *base_addr; size_t offset; long dtype; struct D dim[2]; }; void foo (void) { extern void baz (struct A1 *); struct A1 a1 = { 0, 0, 0, { { 0, 0, 0 } } }; baz (&a1); } void bar (void) { extern void baz (struct A2 *); struct A2 a2 = { 0, 0, 0, { { 0, 0, 0 }, { 0, 0, 0 } } }; baz (&a2); } Above, A stands for generic real(8) array descriptor type that supports up to maximum number of dimensions, A1 for rank 1 and A2 for rank 2 real(8) array descriptor. IMHO you want instead: typedef __SIZE_TYPE__ size_t; struct D { long stride, lower_bound, ubound; }; struct A { float *base_addr; size_t offset; long dtype; struct D dim[7]; }; struct A1 { float *base_addr; size_t offset; long dtype; struct D dim[1]; }; struct A2 { float *base_addr; size_t offset; long dtype; struct D dim[2]; }; void foo (void) { extern void baz (struct A *); struct A1 a1 = { 0, 0, 0, { { 0, 0, 0 } } }; baz ((struct A *) &a1); } void bar (void) { extern void baz (struct A *); struct A2 a2 = { 0, 0, 0, { { 0, 0, 0 }, { 0, 0, 0 } } }; baz ((struct A *) &a2); } and ensure that A/A1/A2 etc. (the various types created by gfc_get_array_type_bounds) have the same TYPE_ALIAS to make the alias oracle happy. I hope only the libgfortran intrinsics that handle various ranks by the same function are a problem, therefore I'd say you should be marking the symbols for those intrinsics with some flag that you want to treat their arguments like assumed rank arrays, and then just cast the addresses of the descriptors you want to pass to them to some reference type to assumed rank descriptor type (dunno if just array7_real(kind=8) (i.e. maximum rank), or something else). Now, the question is if this affects just the intrinsic routines from libgfortran, or user written functions/subroutines too. I hope the latter only should be called with the right rank except for assumed