Bug 53971 - [OOP] Class container - reverse order of _vtab and _data
Summary: [OOP] Class container - reverse order of _vtab and _data
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-15 09:27 UTC by Tobias Burnus
Modified: 2017-07-27 19:59 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-21 00:00:00


Attachments
Draft patch - should be sufficient, but isn't. (1.06 KB, patch)
2012-07-15 09:27 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-07-15 09:27:57 UTC
Created attachment 27798 [details]
Draft patch - should be sufficient, but isn't.

The main purpose of the proposed change is the handling of assumed-rank arrays, both implementation wise and by allowing to bump the MAX_DIMENSION without breaking the ABI.

The attached patch should be sufficient, but it causes many test suite failures, e.g. by having a __vtype in the call to class.c's find_typebound_proc_uop. For that argument, derived->f2k_derived == NULL, which triggers an assert for gfortran.dg/abstract_type_6.f03.



Currently, the first element in a class container is _data, followed by _vptr.

_data can be either directly a memory address or array descriptor of rank n. Hence, the byte-offset between the base address of the class container and the _vptr depends on the kind of data (normal scalar vs. array) and the rank.

For assumed-shape arrays, that implies that one always needs to have an array descriptor of MAX_DIMENSION – and changing MAX_DIMENSION will break the arrays.

If one reorder _vptr and _data, _vptr can be always accessed and one can directly pass class containers (with descriptor) of any rank – the size of the array container is then known at run time based on the rank information.

In C syntax, that's

{
   void *_vpt;
   {
     /* First fields of the array descriptor.  */
     array_dim_triplet dim[ ];
   }
}

Where the "[ ]" allows for different lengths; it is created by creating a tree-decl for an array of size 0.

The current assumed-rank patch, has always MAX_DIMENSION and copies all fields including the dimension triplet (the latter via range-ref) over.
Comment 1 Mikael Morin 2012-07-15 12:27:49 UTC
(In reply to comment #0)
> The attached patch should be sufficient, but it causes many test suite
> failures, e.g. by having a __vtype in the call to class.c's
> find_typebound_proc_uop. For that argument, derived->f2k_derived == NULL, which
> triggers an assert for gfortran.dg/abstract_type_6.f03.
> 
Hello, you may also look at conv_parent_component_references.
This function is normally used with extended derived types to access a field in the base object: an implicit reference to the base type object (first field in the extended one) is automatically added.
I don't remember the details, but I think that in some cases, it was fed with a class container and was also doing the "right" thing in those cases (accessing the object itself, and then one of its subfield).
Not sure whether it is relevant anymore as we now have calls to gfc_fix_class_refs, which makes the implicit references explicit.

Anyway, even if it's not anymore relevant, I'm afraid there are many places we use derived->components where we should have used gfc_find_component(derived, "_data") :-(.
Comment 2 Dominique d'Humieres 2014-12-21 15:13:00 UTC
Any progress?
Comment 3 Eric Gallager 2017-07-27 19:59:14 UTC
(In reply to Dominique d'Humieres from comment #2)
> Any progress?

Guess not; closing for being stuck in WAITING for so long