Fortran LTO and array descriptors.

Jakub Jelinek jakub@redhat.com
Mon Feb 5 07:54:00 GMT 2018


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.

	Jakub



More information about the Fortran mailing list