public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pault at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/29397] Constant logical expression with parameter array
Date: Mon, 07 May 2007 04:44:00 -0000	[thread overview]
Message-ID: <20070507044448.14386.qmail@sourceware.org> (raw)
In-Reply-To: <bug-29397-10259@http.gcc.gnu.org/bugzilla/>



------- Comment #7 from pault at gcc dot gnu dot org  2007-05-07 05:44 -------
The patch below works and regtests.  Before submitting it, however, I would
like to understand why I could not persuade the use of the repeat count to
work, rather than expanding to a full array.

Paul

Index: gcc/fortran/decl.c
===================================================================
*** gcc/fortran/decl.c  (revision 124474)
--- gcc/fortran/decl.c  (working copy)
*************** add_init_expr_to_sym (const char *name, 
*** 974,980 ****

        /* Add initializer.  Make sure we keep the ranks sane.  */
        if (sym->attr.dimension && init->rank == 0)
!       init->rank = sym->as->rank;

        sym->value = init;
        *initp = NULL;
--- 974,1004 ----

        /* Add initializer.  Make sure we keep the ranks sane.  */
        if (sym->attr.dimension && init->rank == 0)
!       {
!         mpz_t size;
!         gfc_constructor *ctor, *tail;
!         int n;
!         if (sym->attr.flavor == FL_PARAMETER
!               && init->expr_type == EXPR_CONSTANT
!               && spec_size (sym->as, &size) == SUCCESS
!               && mpz_cmp_si (size, 0) > 0)
!           {
!             ctor = tail = gfc_get_constructor ();
!             ctor->expr = init;
!             for (n = 1; n < (int)mpz_get_si (size); n++)
!               {
!                 tail->next = gfc_get_constructor ();
!                 tail = tail->next;
!                 tail->expr = gfc_copy_expr (init);
!               }
!             init = gfc_get_expr ();
!             init->expr_type = EXPR_ARRAY;
!             init->ts = ctor->expr->ts;
!             init->value.constructor = ctor;
!             mpz_clear (size);
!           }
!         init->rank = sym->as->rank;
!       }

        sym->value = init;
        *initp = NULL;
Index: gcc/testsuite/gfortran.dg/parameter_array_init_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/parameter_array_init_1.f90        (revision 0)
--- gcc/testsuite/gfortran.dg/parameter_array_init_1.f90        (revision 0)
***************
*** 0 ****
--- 1,11 ----
+ ! { dg-do compile }
+ ! tests the fix for PR29397, in which the initializer for the parameter
+ ! 'J' was not expanded into an array.
+ !
+ ! Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+ !
+   INTEGER :: K(3) = 1
+   INTEGER, PARAMETER :: J(3) = 2
+   IF (ANY (MAXLOC (K, J<3) .NE. 1)) CALL ABORT ()
+   IF (ANY (J .NE. 2)) CALL ABORT ()
+ END


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-02-09 22:42:15         |2007-05-07 05:44:48
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29397


      parent reply	other threads:[~2007-05-07  4:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-08 21:50 [Bug fortran/29397] New: Problem with MAXLOC where mask involves a " fxcoudert at gcc dot gnu dot org
2006-10-08 21:50 ` [Bug fortran/29397] " fxcoudert at gcc dot gnu dot org
2006-10-25 20:39 ` [Bug fortran/29397] Constant logical expression with " tkoenig at gcc dot gnu dot org
2007-02-06 14:05 ` fxcoudert at gcc dot gnu dot org
2007-02-09 22:42 ` fxcoudert at gcc dot gnu dot org
2007-03-17 15:28 ` tkoenig at gcc dot gnu dot org
2007-04-13 21:26 ` pault at gcc dot gnu dot org
2007-04-13 22:25 ` pault at gcc dot gnu dot org
2007-05-07  4:44 ` pault at gcc dot gnu dot org [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=20070507044448.14386.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).