public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tobias Burnus <burnus@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-11] Fortran/OpenMP: class.cc fix for mapping of DT with allocatable components
Date: Wed,  2 Mar 2022 22:22:01 +0000 (GMT)	[thread overview]
Message-ID: <20220302222201.5F65B3858406@sourceware.org> (raw)

https://gcc.gnu.org/g:c0d260e27e7132e3696a5d6d0ded3ed39cc4bca5

commit c0d260e27e7132e3696a5d6d0ded3ed39cc4bca5
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Mar 2 20:02:15 2022 +0100

    Fortran/OpenMP: class.cc fix for mapping of DT with allocatable components
    
        This commit: OG11 version.
        GCC 12/mainline submission (previous commit and this follow up):
        https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591144.html
    
        gcc/fortran/ChangeLog:
    
                * class.c (generate_callback_wrapper): Fixes.

Diff:
---
 gcc/fortran/class.c | 66 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index 26f9a7e4e93..d6fb5e782e7 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -2300,9 +2300,9 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
   gfc_namespace *sub_ns;
   gfc_code *last_code, *block;
   gfc_symbol *callback, *cb, *token, *this_ptr, *scalar, *flag, *result;
-  gfc_symbol *c_ptr, *c_funptr, *c_null_funptr, *c_short;
+  gfc_symbol *c_ptr, *c_funptr, *c_null_funptr, *c_short, *c_size_t;
   gfc_expr *size;
-  int c_short_kind;
+  int c_short_kind, c_size_kind;
   char *name;
 
   /* Set up the namespace.  */
@@ -2320,6 +2320,8 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
   gfc_find_symbol ("c_null_funptr", sub_ns, 0, &c_null_funptr);
   gfc_find_symbol ("c_short", sub_ns, 0, &c_short);
   c_short_kind = mpz_get_si (c_short->value->value.integer);
+  gfc_find_symbol ("c_size_t", sub_ns, 0, &c_size_t);
+  c_size_kind = mpz_get_si (c_size_t->value->value.integer);
 
   /* Set up the procedure symbol.  */
   name = xasprintf ("__callback_%s", tname);
@@ -2512,7 +2514,7 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
   block->expr2->where = gfc_current_locus;
   block->expr2->symtree = gfc_find_symtree (sub_ns->sym_root, cb->name);
   block->expr2->value.function.esym = cb;
-  block->expr2->value.function.esym->name = cb->name;
+  block->expr2->value.function.name = cb->name;
   block->expr2->value.function.actual = gfc_get_actual_arglist ();
   block->expr2->value.function.actual->expr = gfc_lval_expr_from_sym (token);
   block->expr2->value.function.actual->next = gfc_get_actual_arglist ();
@@ -2642,7 +2644,9 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
       loc_expr->symtree->n.sym->intmod_sym_id = ISOCBINDING_LOC;
       loc_expr->symtree->n.sym->attr.intrinsic = 1;
       loc_expr->symtree->n.sym->from_intmod = INTMOD_ISO_C_BINDING;
-      loc_expr->value.function.isym = gfc_intrinsic_function_by_id (GFC_ISYM_C_LOC);
+      loc_expr->value.function.isym
+	= gfc_intrinsic_function_by_id (GFC_ISYM_C_LOC);
+      loc_expr->value.function.name = loc_expr->value.function.isym->name;
       loc_expr->value.function.actual = gfc_get_actual_arglist ();
       loc_expr->value.function.actual->expr = expr;
       loc_expr->symtree->n.sym->result = expr->symtree->n.sym;
@@ -2668,7 +2672,7 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
       e->where = gfc_current_locus;
       e->symtree = gfc_find_symtree (sub_ns->sym_root, cb->name);
       e->value.function.esym = cb;
-      e->value.function.esym->name = cb->name;
+      e->value.function.name = cb->name;
       e->value.function.actual = gfc_get_actual_arglist ();
       e->value.function.actual->expr = gfc_lval_expr_from_sym (token);
       e->value.function.actual->next = gfc_get_actual_arglist ();
@@ -2692,6 +2696,16 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
 	  || pointer || proc_ptr)
 	continue;
 
+      /* TODO: Handle unlimited polymorphic components.  */
+      if (comp->ts.type == BT_CLASS
+	  && CLASS_DATA (comp)->ts.u.derived->attr.unlimited_polymorphic)
+	continue;
+
+      /* TODO: Handle unlimited polymorphic components.  */
+      if (comp->ts.type == BT_CLASS
+	  && comp->ts.u.derived->attr.unlimited_polymorphic)
+	continue;
+
       gfc_expr *vtab_cb_expr;
       if (comp->ts.type == BT_DERIVED)
 	vtab_cb_expr = gfc_lval_expr_from_sym (gfc_find_vtab (&comp->ts));
@@ -2718,6 +2732,38 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
       block->expr2->value.op.op2 = gfc_get_expr ();
       e = block->expr2->value.op.op2;
 
+      /* size:  storage_size(comp_expr) / storage_size(0_1), where the
+	 denominator is BITS_PER_UNIT as bit_size = kind * BITS_PER_UNIT.  */
+      size = gfc_get_expr ();
+      size->expr_type = EXPR_OP;
+      size->where = gfc_current_locus;
+      size->ts.type = BT_INTEGER;
+      size->ts.kind = c_size_kind;
+      size->value.op.op = INTRINSIC_DIVIDE;
+      size->value.op.op1 = gfc_get_expr ();
+      size->value.op.op1->ts = size->ts;
+      size->value.op.op1->expr_type = EXPR_FUNCTION;
+      size->value.op.op1->value.function.isym
+	= gfc_intrinsic_function_by_id (GFC_ISYM_STORAGE_SIZE);
+      size->value.op.op1->value.function.name
+	= size->value.op.op1->value.function.isym->name;
+      size->value.op.op1->value.function.esym = NULL;
+      size->value.op.op1->value.function.actual = gfc_get_actual_arglist ();
+      size->value.op.op1->value.function.actual->expr = gfc_copy_expr (expr);
+      size->value.op.op1->where = gfc_current_locus;
+      size->value.op.op2 = gfc_get_expr ();
+      size->value.op.op2->ts = size->ts;
+      size->value.op.op2->expr_type = EXPR_FUNCTION;
+      size->value.op.op2->value.function.isym
+	= gfc_intrinsic_function_by_id (GFC_ISYM_STORAGE_SIZE);
+      size->value.op.op2->value.function.name
+	= size->value.op.op2->value.function.isym->name;
+      size->value.op.op2->value.function.esym = NULL;
+      size->value.op.op2->value.function.actual = gfc_get_actual_arglist ();
+      size->value.op.op2->value.function.actual->expr
+	= gfc_get_int_expr (/* kind = */ 1, NULL, 0);
+      size->value.op.op2->where = gfc_current_locus;
+
       if (comp->attr.dimension)
 	{
 	  e->expr_type = EXPR_FUNCTION;
@@ -2738,17 +2784,19 @@ generate_callback_wrapper (gfc_symbol *vtab, gfc_symbol *derived,
       e->where = gfc_current_locus;
       e->symtree = gfc_find_symtree (sub_ns->sym_root, cb->name);
       e->value.function.esym = cb;
-      e->value.function.esym->name = cb->name;
+      e->value.function.name = cb->name;
       e->value.function.actual = gfc_get_actual_arglist ();
       e->value.function.actual->expr = gfc_lval_expr_from_sym (token);
       e->value.function.actual->next = gfc_get_actual_arglist ();
       e->value.function.actual->next->expr = gfc_copy_expr (expr);
       e->value.function.actual->next->next = gfc_get_actual_arglist ();
-      e->value.function.actual->next->next->expr
+      e->value.function.actual->next->next->expr = size;
+      e->value.function.actual->next->next->next = gfc_get_actual_arglist ();
+      e->value.function.actual->next->next->next->expr
 	= gfc_get_int_expr (gfc_index_integer_kind, NULL,
 			    GFC_CLASS_CB_ALLOCATABLE);
-      e->value.function.actual->next->next->next = gfc_get_actual_arglist ();
-      e->value.function.actual->next->next->next->expr = vtab_cb_expr;
+      e->value.function.actual->next->next->next->next = gfc_get_actual_arglist ();
+      e->value.function.actual->next->next->next->next->expr = vtab_cb_expr;
     }
 
   vtab_cb->initializer = gfc_lval_expr_from_sym (callback);


                 reply	other threads:[~2022-03-02 22:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220302222201.5F65B3858406@sourceware.org \
    --to=burnus@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).