public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Thomas Koenig <tkoenig@netcologne.de>,
	    "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
Subject: Re: Fortran LTO and array descriptors.
Date: Mon, 05 Feb 2018 10:17:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1802051113290.18265@zhemvz.fhfr.qr> (raw)
In-Reply-To: <20180203173119.GB28993@laptop.zalov.cz>

On Sat, 3 Feb 2018, Jakub Jelinek wrote:

> On Sat, Feb 03, 2018 at 06:09:41PM +0100, Thomas Koenig wrote:
> > I have been looking at PR 68649 and 68717. They are the
> > same bug, really (and there are quite a few more).
> > 
> > Jakub has written a good analysis of the problem at
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68649#c12 .
> > 
> > To sum it up, we create different types for each rank of
> > array, and then call the library. When we call the
> > same function with different ranks, lto complains, with
> > good reason.
> > 
> > The last comment, by Richard, ends with the rather
> > pessimistic "Thus even the proposed fix won't end up working."
> > 
> > This problem prevents users from a lot of LTO use cases. It also
> > prevents us from using LTO with the library (although I
> > strongly suspect that there are also other stumbling blocks).
> > 
> > So, what to do?  On the libfortran side, I tried out the patch
> 
> Trying Richi's testcase with real flexible array member doesn't help:
> struct Xflex
> {
>   int n;
>   int a[];
> };
> struct Xspecific
> {
>   int n;
>   int a[7];
> } x;
> 
> int
> foo (struct Xflex *f)
> {
>   f->a[6] = 2;
>   x.a[6] = 1;
>   return f->a[6];
> }
> 
> still returns 2 at -O2.  What seems to work is:
> struct Xflex
> {
>   int n;
>   int a[];
> };
> union Uspecific
> {
> struct Xflex flex;
> struct Xspecific
> {
>   int n;
>   int a[7];
> } specific;
> } x;
> 
> int
> foo (struct Xflex *f)
> {
>   f->a[6] = 2;
>   x.specific.a[6] = 1;
>   return f->a[6];
> }
> 
> i.e. have a generic struct with flexible array member, which is what e.g.
> the libgfortran APIs take as arguments, and when you actually need an object
> on the stack or static object, make it a union of that generic struct with
> flexible array member and the struct specific for how big rank you want.
> 
> I can try to implement that next week if that's what we agree on.

Note given you control what IL is presented to GCC in the Fortran FE
you don't need to jump through hoops using a union -- you can
rely on the middle-end behavior and simply emit code as if you'd
write in C:

 ((struct Xflex *)&x)->a[6] = 1;

or in GENERIC terms you wrap the Xspecific objects in
a MEM_REF with operand 1 being build_int_cst (pointer_to_Xflex_type_node, 
0) which tells GCC to use the alias-set of Xflex.

So wherever you build "decls" of one of the array-descriptor types
(or embed them into a struct!) when you access the descriptor
use the trailing-array variant.

I think I've seen all array descriptor accesses code-generation
abstracted away in some helper routines.

Richard.

      reply	other threads:[~2018-02-05 10:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-03 17:09 Thomas Koenig
2018-02-03 17:17 ` Thomas Koenig
2018-02-04 11:42   ` Richard Biener
2018-02-04 11:48     ` Richard Biener
2018-02-04 20:15     ` Thomas Koenig
2018-02-05  6:42       ` Richard Biener
2018-02-04 12:36 ` Richard Biener
2018-02-05  7:54 ` Jakub Jelinek
2018-02-05 10:17   ` Richard Biener [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.1802051113290.18265@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=fortran@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=tkoenig@netcologne.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).