On Sun, Aug 29, 2021 at 10:07 AM Tobias Burnus <tob...@codesourcery.com> wrote: > > Hi all, hi Richard, > > On 27.08.21 21:48, Richard Biener wrote: > >> It looks really nice with "-O1 -fno-inline" :-) > >> The callee 'rank_p()' is mostly optimized and in the > >> caller only those struct elements are set, which are used: > >> > >> integer(kind=4) rank_p (struct CFI_cdesc_t & _this) > >> { > >> _1 = _this_11(D)->base_addr; > >> _2 = _this_11(D)->rank; > >> ... > >> rnk_13 = (integer(kind=4)) _2; > >> return rnk_13; > >> } > >> > >> void selr_p () > >> { > >> ... > >> struct CFI_cdesc_t01 cfi.7; > >> ... > >> <bb 2> [local count: 537730764]: > >> cfi.7.rank = 1; > >> cfi.7.base_addr = 0B; > > You need to do the accesses above using the generic 't' type as well, > > otherwise they are non-conflicting TBAA wise. > > First, I wonder why the following works with C: > > struct gen_t { int n; int dim[]; } > > int f (struct gen_t *x) { > if (x->n > 1) x->dim[0] = 5; > return x->n; > } > > void test() { > struct { int n; int dim[2]; } y; > y.n = 2; > f ((struct gen_t*) &y); > } > > Or doesn't it?
It probably doesn't and suffers from the same issue as your original fortran code. >In any case, that's how it is suggested > and 'y.n' is not accessed using 'gen_t' – there is only > a cast in the function call. (Which is not sufficient > in the Fortran FE-code generated code – as tried) > > * * * > > Otherwise, I can confirm that the following works. > Does this original dump now looks fine? > > struct CFI_cdesc_t01 cfi.2; > ... > ((struct CFI_cdesc_t *) &cfi.2)->version = 1; > ((struct CFI_cdesc_t *) &cfi.2)->rank = 1; > ((struct CFI_cdesc_t *) &cfi.2)->type = 1025; > ((struct CFI_cdesc_t *) &cfi.2)->attribute = 0; > ((struct CFI_cdesc_t *) &cfi.2)->base_addr = intp.data; > ((struct CFI_cdesc_t *) &cfi.2)->elem_len = 4; > ... > irnk = rank_p ((struct CFI_cdesc_t *) &cfi.2); Yes, that looks OK now. The idea is you can use the complete types for storage allocation but you _always_ have to use the incomplete (with flexarray member) type for all accesses. Richard. > Thanks, > > Tobias > > ----------------- > Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 > München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas > Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht > München, HRB 106955