From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: Andre Vehreschild <vehre@gmx.de>
Cc: Mikael Morin <mikael.morin@sfr.fr>,
GCC-Fortran-ML <fortran@gcc.gnu.org>,
GCC-Patches-ML <gcc-patches@gcc.gnu.org>,
Antony Lewis <antony@cosmologist.info>
Subject: Re: [Patch 1/2, Fortran, pr60322] [OOP] Incorrect bounds on polymorphic dummy array
Date: Tue, 24 Mar 2015 10:13:00 -0000 [thread overview]
Message-ID: <CAGkQGiK2sp2wqXLMPvg8bc=vgJyr9jryukvwML9Jc9+yt_9odA@mail.gmail.com> (raw)
In-Reply-To: <20150323134357.6af740d1@vepi2>
Dear Andre,
Dominique pointed out to me that the 'loc' patch causes a ICE in the
testsuite. It seems that 'loc' should provide the address of the class
container in some places and the address of the data in others. I will
put my thinking cap on tonight :-)
Cheers
Paul
On 23 March 2015 at 13:43, Andre Vehreschild <vehre@gmx.de> wrote:
> Hi Mikael,
>
> thanks for looking at the patch. Please note, that Paul has sent an addendum to
> the patches for 60322, which I deliberately have attached.
>
>> 26/02/2015 18:17, Andre Vehreschild a écrit :
>> > This first patch is only preparatory and does not change any of the
>> > semantics of gfortran at all.
>> Sure?
>
> With the counterexample you found below, this of course is a wrong statement.
>
>> > diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
>> > index ab6f7a5..d28cf77 100644
>> > --- a/gcc/fortran/expr.c
>> > +++ b/gcc/fortran/expr.c
>> > @@ -4059,10 +4060,10 @@ gfc_lval_expr_from_sym (gfc_symbol *sym)
>> > lval->symtree = gfc_find_symtree (sym->ns->sym_root, sym->name);
>> >
>> > /* It will always be a full array. */
>> > - lval->rank = sym->as ? sym->as->rank : 0;
>> > + as = sym->as;
>> > + lval->rank = as ? as->rank : 0;
>> > if (lval->rank)
>> > - gfc_add_full_array_ref (lval, sym->ts.type == BT_CLASS ?
>> > - CLASS_DATA (sym)->as : sym->as);
>> > + gfc_add_full_array_ref (lval, as);
>>
>> This is a change of semantics. Or do you know that sym->ts.type !=
>> BT_CLASS?
>
> You are completely right. I have made a mistake here. I have to tell the truth,
> I never ran a regtest with only part 1 of the patches applied. The second part
> of the patch will correct this, by setting the variable as depending on whether
> type == BT_CLASS or not. Sorry for the mistake.
>
>> > diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
>> > index 3664824..e571a17 100644
>> > --- a/gcc/fortran/trans-decl.c
>> > +++ b/gcc/fortran/trans-decl.c
>> > @@ -1013,16 +1017,24 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree
>> > dummy) tree decl;
>> > tree type;
>> > gfc_array_spec *as;
>> > + symbol_attribute *array_attr;
>> > char *name;
>> > gfc_packed packed;
>> > int n;
>> > bool known_size;
>> >
>> > - if (sym->attr.pointer || sym->attr.allocatable
>> > - || (sym->as && sym->as->type == AS_ASSUMED_RANK))
>> > + /* Use the array as and attr. */
>> > + as = sym->as;
>> > + array_attr = &sym->attr;
>> > +
>> > + /* The pointer attribute is always set on a _data component, therefore
>> > check
>> > + the sym's attribute only. */
>> > + if (sym->attr.pointer || array_attr->allocatable
>> > + || (as && as->type == AS_ASSUMED_RANK))
>> > return dummy;
>> >
>> Any reason to sometimes use array_attr, sometimes not, like here?
>> By the way, the comment is misleading: for classes, there is the
>> class_pointer attribute (and it is a pain, I know).
>
> Yes, and a good one. Array_attr is sometimes sym->attr and sometimes
> CLASS_DATA(sym)->attr aka sym->ts.u.derived->components->attr. In the later
> case .pointer is always set to 1 in the _data component's attr. I.e., the above
> if, would always yield true for a class_array, which is not intended, but rather
> destructive. I know about the class_pointer attribute, but I figured, that it
> is not relevant here. Any idea how to formulate the comment better, to reflect
> what I just explained?
>
> Regards,
> Andre
> --
> Andre Vehreschild * Email: vehre ad gmx dot de
>
>
> ---------- Forwarded message ----------
> From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
> To: Andre Vehreschild <vehre@gmx.de>, Dominique Dhumieres <dominiq@lps.ens.fr>
> Cc:
> Date: Sun, 22 Mar 2015 21:20:20 +0100
> Subject: Bug in intrinsic LOC for scalar class objects
> Dear Andre and Dominique,
>
> I have found that LOC is returning the address of the class container
> rather than the _data component for class scalars. See the source
> below, which you will recognise! A fix is attached.
>
> Note that the scalar allocate fails with MOLD= and so I substituted SOURCE=.
>
> Cheers
>
> Paul
>
> class(*), allocatable :: a(:), e ! Change 'e' to an array and
> second memcpy works correctly
> ! Problem is with loc(e), which
> returns the address of the
> ! class container.
> allocate (e, source = 99.0)
> allocate (a(2), source = [1.0, 2.0])
> call add_element_poly (a,e)
> select type (a)
> type is (real)
> print *, a
> end select
>
> contains
>
> subroutine add_element_poly(a,e)
> use iso_c_binding
> class(*),allocatable,intent(inout),target :: a(:)
> class(*),intent(in),target :: e
> class(*),allocatable,target :: tmp(:)
> type(c_ptr) :: dummy
>
> interface
> function memcpy(dest,src,n) bind(C,name="memcpy") result(res)
> import
> type(c_ptr) :: res
> integer(c_intptr_t),value :: dest
> integer(c_intptr_t),value :: src
> integer(c_size_t),value :: n
> end function
> end interface
>
> if (.not.allocated(a)) then
> allocate(a(1), source=e)
> else
> allocate(tmp(size(a)),source=a)
> deallocate(a)
> allocate(a(size(tmp)+1),source=e) ! mold gives a segfault
> dummy = memcpy(loc(a(1)),loc(tmp),sizeof(tmp))
> dummy = memcpy(loc(a(size(tmp)+1)),loc(e),sizeof(e))
> end if
> end subroutine
> end
>
--
Outside of a dog, a book is a man's best friend. Inside of a dog it's
too dark to read.
Groucho Marx
next prev parent reply other threads:[~2015-03-24 10:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-26 17:19 Andre Vehreschild
2015-03-23 12:29 ` Mikael Morin
2015-03-23 12:44 ` Andre Vehreschild
2015-03-23 14:58 ` Mikael Morin
2015-03-23 15:49 ` Andre Vehreschild
2015-03-23 19:28 ` Mikael Morin
2015-03-24 10:13 ` Paul Richard Thomas [this message]
2015-03-24 17:06 ` [Patch, Fortran, pr60322] was: " Andre Vehreschild
2015-03-25 9:43 ` Dominique d'Humières
2015-03-25 16:57 ` Andre Vehreschild
2015-03-26 9:27 ` Dominique d'Humières
2015-03-27 12:48 ` Paul Richard Thomas
2015-04-05 9:13 ` Paul Richard Thomas
2015-04-09 12:37 ` Andre Vehreschild
2015-04-14 17:01 ` [Patch, Fortran, pr60322, addendum] " Andre Vehreschild
2015-04-16 19:13 ` Paul Richard Thomas
2015-04-23 11:34 ` [commited, Patch, " Andre Vehreschild
2015-04-27 17:43 ` Andre Vehreschild
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='CAGkQGiK2sp2wqXLMPvg8bc=vgJyr9jryukvwML9Jc9+yt_9odA@mail.gmail.com' \
--to=paul.richard.thomas@gmail.com \
--cc=antony@cosmologist.info \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=mikael.morin@sfr.fr \
--cc=vehre@gmx.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).