public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c
@ 2011-08-13  7:12 zeccav at gmail dot com
  2011-08-13 11:23 ` [Bug fortran/50070] " janus at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: zeccav at gmail dot com @ 2011-08-13  7:12 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50070
           Summary: Segmentation fault at size_binop_loc in fold-const.c
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zeccav@gmail.com


Created attachment 24998
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24998
just compile it

gfortran compiler Segmentation fault at size_binop_loc in fold-const.c


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
@ 2011-08-13 11:23 ` janus at gcc dot gnu.org
  2011-08-13 12:06 ` janus at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-13 11:23 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janus at gcc dot gnu.org

--- Comment #1 from janus at gcc dot gnu.org 2011-08-13 11:22:45 UTC ---
I can confirm the segfault with 4.5, 4.6 and 4.7 (trunk) on the test case in
comment #0:


subroutine sub
  common n,z
  character(n) z 
end


However, when removing the subroutine line, I get:

  common n,z
            1
Error: 'z' at (1) must have constant character length in this context


And on the following variant

subroutine sub
  common z
  character(n) z 
end

one get's a different error:

  character(n) z 
            1
Error: Variable 'n' cannot appear in the expression at (1)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
  2011-08-13 11:23 ` [Bug fortran/50070] " janus at gcc dot gnu.org
@ 2011-08-13 12:06 ` janus at gcc dot gnu.org
  2011-08-13 12:09 ` janus at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-13 12:06 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
      Known to fail|                            |4.1.2, 4.4.4, 4.5.4, 4.6.2,
                   |                            |4.7.0

--- Comment #2 from janus at gcc dot gnu.org 2011-08-13 11:53:58 UTC ---
(In reply to comment #1)
> I can confirm the segfault with 4.5, 4.6 and 4.7 (trunk) on the test case in
> comment #0:

Same with 4.4 and 4.1. Apparently this bug has been existing forever.


ifort rejects the original test case with:

error #6756: A COMMON block data object must not be an automatic object.   [Z]
  common n,z
-----------^


g95 says:

  common n,z
           1
Error: Character variable 'z' at (1) must have a constant length


I assume this is an ice-on-invalid-code.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
  2011-08-13 11:23 ` [Bug fortran/50070] " janus at gcc dot gnu.org
  2011-08-13 12:06 ` janus at gcc dot gnu.org
@ 2011-08-13 12:09 ` janus at gcc dot gnu.org
  2011-08-14 12:08 ` janus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-13 12:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from janus at gcc dot gnu.org 2011-08-13 12:05:31 UTC ---
(In reply to comment #2)
> I assume this is an ice-on-invalid-code.

The relevant quote from the F08 std is probably:

"C417 (R422) A type-param-value in a char-length shall be a colon, asterisk, or
specification-expr."

together with chapter 7.1.11 ("Specification expression").


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (2 preceding siblings ...)
  2011-08-13 12:09 ` janus at gcc dot gnu.org
@ 2011-08-14 12:08 ` janus at gcc dot gnu.org
  2011-08-14 12:25 ` janus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-14 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from janus at gcc dot gnu.org 2011-08-14 12:02:57 UTC ---
(In reply to comment #3)
> The relevant quote from the F08 std is probably:
> 
> "C417 (R422) A type-param-value in a char-length shall be a colon, asterisk, or
> specification-expr."
> 
> together with chapter 7.1.11 ("Specification expression").


Based on chapter 7.1.11, I would say that g95's error message is wrong: z does
not have to have constant length.

"A specification-expr shall be a constant expression unless it is in an
interface body (12.4.3.2), the specification part of a subprogram or BLOCK
construct, a derived type definition, or the declaration-type-spec of a FUNCTION
statement (12.6.2.2)."

Since z is in the specification part of a subprogram, there is no need for to
have constant length.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (3 preceding siblings ...)
  2011-08-14 12:08 ` janus at gcc dot gnu.org
@ 2011-08-14 12:25 ` janus at gcc dot gnu.org
  2011-08-14 13:21 ` janus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-14 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from janus at gcc dot gnu.org 2011-08-14 12:07:55 UTC ---
(In reply to comment #2)
> ifort rejects the original test case with:
> 
> error #6756: A COMMON block data object must not be an automatic object.   [Z]
>   common n,z
> -----------^

ifort's error message is apparently based on this restriction in the F08
standard:

"C5100 (R569) A common-block-object shall not be a dummy argument, a result
variable, an allocatable variable, a derived-type object with an ultimate
component that is allocatable, a procedure pointer, an automatic object, a
variable with the BIND attribute, an unlimited polymorphic pointer, or a
coarray."

This is what really makes the original test case invalid.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (4 preceding siblings ...)
  2011-08-14 12:25 ` janus at gcc dot gnu.org
@ 2011-08-14 13:21 ` janus at gcc dot gnu.org
  2011-08-14 14:11 ` dominiq at lps dot ens.fr
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-14 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-08-14
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #6 from janus at gcc dot gnu.org 2011-08-14 13:10:57 UTC ---
Here is a preliminary patch which rejects the original test case:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 177744)
+++ gcc/fortran/resolve.c    (working copy)
@@ -858,6 +858,12 @@ resolve_common_vars (gfc_symbol *sym, bool named_c
                 &csym->declared_at);
     }

+      /* F08:C5100.  */
+      if (csym->ts.type == BT_CHARACTER
+      && !gfc_is_constant_expr (csym->ts.u.cl->length))
+    gfc_error_now ("Automatic object %s at %L may not be in a COMMON block",
+               csym->name, &csym->declared_at);
+
       if (csym->ts.type != BT_DERIVED)
     continue;


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (5 preceding siblings ...)
  2011-08-14 13:21 ` janus at gcc dot gnu.org
@ 2011-08-14 14:11 ` dominiq at lps dot ens.fr
  2011-08-15  9:20 ` janus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-08-14 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-08-14 13:20:27 UTC ---
(In reply to comment #5)
For the record, F95 and F2003 have a similar constraint, respectively:

Constraint: A common-block-object shall not be a dummy argument, an allocatable
array, an automatic
object, a function name, an entry name, or a result name.

C588 (R558) A common-block-object shall not be a dummy argument, an allocatable
variable, a
derived-type object with an ultimate component that is allocatable, an
automatic object, a
function name, an entry name, a variable with the BIND attribute, or a result
name.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (6 preceding siblings ...)
  2011-08-14 14:11 ` dominiq at lps dot ens.fr
@ 2011-08-15  9:20 ` janus at gcc dot gnu.org
  2011-08-15  9:53 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-15  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from janus at gcc dot gnu.org 2011-08-15 09:15:36 UTC ---
(In reply to comment #4)
> Based on chapter 7.1.11, I would say that g95's error message is wrong: z does
> not have to have constant length.

Well, to be precise, it is not really wrong. In the end it enforces the same
restriction as ifort's error message, but in a different wording.

ifort's message is surely closer to the standard, while g95's may be clearer to
people who are not familiar with the standard's definition of "automatic
objects".

So, which wording should we choose for gfortran? I would tend to prefer the g95
version ...


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (7 preceding siblings ...)
  2011-08-15  9:20 ` janus at gcc dot gnu.org
@ 2011-08-15  9:53 ` janus at gcc dot gnu.org
  2011-08-16  9:37 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-15  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from janus at gcc dot gnu.org 2011-08-15 09:49:44 UTC ---
Btw, for a related test case ...


subroutine sub
  common n,z
  integer z(n)
end


... gfortran spits out:

  integer z(n)
            1
Error: Variable 'n' at (1) in this context must be constant


Here we also complain about non-constant expressions (instead of "automatic
objects"), so we should probably stick to this kind of wording also for the
original test case (which had non-constant character lengths).


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (8 preceding siblings ...)
  2011-08-15  9:53 ` janus at gcc dot gnu.org
@ 2011-08-16  9:37 ` janus at gcc dot gnu.org
  2011-08-17  9:26 ` janus at gcc dot gnu.org
  2011-08-17 11:13 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-16  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from janus at gcc dot gnu.org 2011-08-16 09:19:07 UTC ---
Here is a patch which rejects the test case with a different error message than
comment #6:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 177779)
+++ gcc/fortran/resolve.c    (working copy)
@@ -10169,15 +10169,22 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)

       if (!gfc_is_constant_expr (e)
       && !(e->expr_type == EXPR_VARIABLE
-           && e->symtree->n.sym->attr.flavor == FL_PARAMETER)
-      && sym->ns->proc_name
-      && (sym->ns->proc_name->attr.flavor == FL_MODULE
-          || sym->ns->proc_name->attr.is_main_program)
-      && !sym->attr.use_assoc)
+           && e->symtree->n.sym->attr.flavor == FL_PARAMETER))
     {
-      gfc_error ("'%s' at %L must have constant character length "
-             "in this context", sym->name, &sym->declared_at);
-      return FAILURE;
+      if (!sym->attr.use_assoc && sym->ns->proc_name
+          && (sym->ns->proc_name->attr.flavor == FL_MODULE
+          || sym->ns->proc_name->attr.is_main_program))
+        {
+          gfc_error ("'%s' at %L must have constant character length "
+            "in this context", sym->name, &sym->declared_at);
+          return FAILURE;
+        }
+      if (sym->attr.in_common)
+        {
+          gfc_error ("COMMON variable '%s' at %L must have constant "
+             "character length", sym->name, &sym->declared_at);
+          return FAILURE;
+        }
     }
     }


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (9 preceding siblings ...)
  2011-08-16  9:37 ` janus at gcc dot gnu.org
@ 2011-08-17  9:26 ` janus at gcc dot gnu.org
  2011-08-17 11:13 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-17  9:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from janus at gcc dot gnu.org 2011-08-17 09:14:24 UTC ---
Author: janus
Date: Wed Aug 17 09:14:18 2011
New Revision: 177825

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177825
Log:
2011-08-17  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/50070
    * resolve.c (resolve_fl_variable): Reject non-constant character lengths
    in COMMON variables.


2011-08-17  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/50070
    * gfortran.dg/common_13.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/common_13.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/50070] Segmentation fault at size_binop_loc in fold-const.c
  2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
                   ` (10 preceding siblings ...)
  2011-08-17  9:26 ` janus at gcc dot gnu.org
@ 2011-08-17 11:13 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-17 11:13 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #12 from janus at gcc dot gnu.org 2011-08-17 09:25:58 UTC ---
Fixed with r177825. Closing.

Thanks for the report!


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-08-17  9:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-13  7:12 [Bug fortran/50070] New: Segmentation fault at size_binop_loc in fold-const.c zeccav at gmail dot com
2011-08-13 11:23 ` [Bug fortran/50070] " janus at gcc dot gnu.org
2011-08-13 12:06 ` janus at gcc dot gnu.org
2011-08-13 12:09 ` janus at gcc dot gnu.org
2011-08-14 12:08 ` janus at gcc dot gnu.org
2011-08-14 12:25 ` janus at gcc dot gnu.org
2011-08-14 13:21 ` janus at gcc dot gnu.org
2011-08-14 14:11 ` dominiq at lps dot ens.fr
2011-08-15  9:20 ` janus at gcc dot gnu.org
2011-08-15  9:53 ` janus at gcc dot gnu.org
2011-08-16  9:37 ` janus at gcc dot gnu.org
2011-08-17  9:26 ` janus at gcc dot gnu.org
2011-08-17 11:13 ` janus at gcc dot gnu.org

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).