public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/67614] New: ICE on using arithmetic if with null
@ 2015-09-17 18:03 gerhard.steinmetz.fortran@t-online.de
  2015-09-17 18:04 ` [Bug fortran/67614] " gerhard.steinmetz.fortran@t-online.de
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gerhard.steinmetz.fortran@t-online.de @ 2015-09-17 18:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

            Bug ID: 67614
           Summary: ICE on using arithmetic if with null
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gerhard.steinmetz.fortran@t-online.de
  Target Milestone: ---

Some cases with oldstyle arithmetic if in combination with null
instead of a scalar-numeric-expr :


$ cat z1.f90
program p
   integer, allocatable :: z
   if ( null(z) ) 1, 2, 3
 1 stop 1
 2 stop 2
 3 stop 3
end

$ gfortran -g -O0 -Wall -fcheck=all -fno-frontend-optimize z1.f90
internal compiler error: in gfc_build_const, at fortran/trans-const.c:76



$ cat z2.f90
program p
   integer, pointer :: z
   if ( null(z) ) 1, 2, 3
 1 stop 1
 2 stop 2
 3 stop 3
end

$ gfortran z2.f90
internal compiler error: in gfc_build_const, at fortran/trans-const.c:76


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
@ 2015-09-17 18:04 ` gerhard.steinmetz.fortran@t-online.de
  2015-09-17 23:03 ` dominiq at lps dot ens.fr
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gerhard.steinmetz.fortran@t-online.de @ 2015-09-17 18:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

--- Comment #1 from Gerhard Steinmetz <gerhard.steinmetz.fortran@t-online.de> ---
$ cat z4.f90
program p
   integer, pointer :: z => null()
   if ( z ) 1, 2, 3
 1 stop 1
 2 stop 2
 3 stop 3
end


$ gfortran -g -O0 -Wall -fcheck=all -fno-frontend-optimize z4.f90
$ a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
  2015-09-17 18:04 ` [Bug fortran/67614] " gerhard.steinmetz.fortran@t-online.de
@ 2015-09-17 23:03 ` dominiq at lps dot ens.fr
  2015-09-23 23:06 ` kargl at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-09-17 23:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-09-17
     Ever confirmed|0                           |1

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed from 4.8 up to trunk (6.0).


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
  2015-09-17 18:04 ` [Bug fortran/67614] " gerhard.steinmetz.fortran@t-online.de
  2015-09-17 23:03 ` dominiq at lps dot ens.fr
@ 2015-09-23 23:06 ` kargl at gcc dot gnu.org
  2015-09-24 14:38 ` gerhard.steinmetz.fortran@t-online.de
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2015-09-23 23:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

kargl at gcc dot gnu.org changed:

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

--- Comment #3 from kargl at gcc dot gnu.org ---
I'm inclined to close this PR as WONTFIX.  The F2008 in
2.4.8 states: "A pointer that is not associated shall
not be referenced or defined."  This is not a numbered
constraint and so a Fortran processor is not required
to report an error.  It is the programmer's responsibility
to ensure that a referenced pointer is associated.

In addition, consider the code

program y1
   real, pointer :: a
   real, target :: b
   b = 42
   a => b
   call foo(a)
   a => null()
   call foo(a)
   contains
      subroutine foo(x)
         real, pointer :: x
         if (2*x+1) 10, 20, 30
10       print *, 'a'; goto 40
20       print *, 'b'; goto 40
30       print *, 'c'; goto 40
40       continue
      end subroutine
end program y1

The evaluation of the scalar-numeric-expr in the
arithmetic-if would requires a runtime check that
x is in fact an associated pointer.  This could 
be rather costly and prevent possible optimizations
if gfortran tried to always ensure any reference
to a pointer is properly associated.

It is the responsibility of the programmer to
write

if (associated(x) then
   if (2*x+1) 10, 20, 30
   ...
end if

Of course, if someone wants to add an -fcheck=pointer-status
option, then problems in this PR can be at least checked.


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
                   ` (2 preceding siblings ...)
  2015-09-23 23:06 ` kargl at gcc dot gnu.org
@ 2015-09-24 14:38 ` gerhard.steinmetz.fortran@t-online.de
  2015-09-24 14:40 ` gerhard.steinmetz.fortran@t-online.de
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gerhard.steinmetz.fortran@t-online.de @ 2015-09-24 14:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

--- Comment #4 from Gerhard Steinmetz <gerhard.steinmetz.fortran@t-online.de> ---
In general, a future extension to check pointer status
looks promising (at compile time and runtime).

With a tiny and simple source the problem is clear and
obvious, but for large and complex codes often not.


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
                   ` (3 preceding siblings ...)
  2015-09-24 14:38 ` gerhard.steinmetz.fortran@t-online.de
@ 2015-09-24 14:40 ` gerhard.steinmetz.fortran@t-online.de
  2015-09-25 22:31 ` kargl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gerhard.steinmetz.fortran@t-online.de @ 2015-09-24 14:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

--- Comment #5 from Gerhard Steinmetz <gerhard.steinmetz.fortran@t-online.de> ---
For comparison, a logical if (assumes scalar-logical-expr
instead of scalar-numeric-expr in arithmetic if) "avoids"
an ICE. Analogous examples :


$ cat y1.f90
program p
   logical, allocatable :: z
   if ( null(z) ) print *, 'a'
end


$ cat y2.f90
program p
   logical, pointer :: z
   if ( null(z) ) print *, 'a'
end


$ cat y7.f90
program p
   logical, allocatable :: z
   if ( null(z) ) then
      print *, 'a'
   else
      print *, 'not a'
   end if
end

$ gfortran -g -O0 -Wall -fcheck=all -fno-frontend-optimize y7.f90
$ a.out
 not a


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
                   ` (4 preceding siblings ...)
  2015-09-24 14:40 ` gerhard.steinmetz.fortran@t-online.de
@ 2015-09-25 22:31 ` kargl at gcc dot gnu.org
  2015-09-25 22:59 ` kargl at gcc dot gnu.org
  2015-09-25 23:03 ` kargl at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2015-09-25 22:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

--- Comment #6 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Fri Sep 25 22:30:26 2015
New Revision: 228156

URL: https://gcc.gnu.org/viewcvs?rev=228156&root=gcc&view=rev
Log:
2015-09-25  Steven G. Kargl  <kargl@gcc.gnu.org>

        PR fortran/67614
        * resolve.c (gfc_resolve_code): Prevent ICE for invalid EXPR_NULL.

2015-09-25  Steven G. Kargl  <kargl@gcc.gnu.org>

        PR fortran/67614
        * gfortran.dg/pr67614.f90: New test.

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


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
                   ` (5 preceding siblings ...)
  2015-09-25 22:31 ` kargl at gcc dot gnu.org
@ 2015-09-25 22:59 ` kargl at gcc dot gnu.org
  2015-09-25 23:03 ` kargl at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2015-09-25 22:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

--- Comment #7 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Fri Sep 25 22:59:15 2015
New Revision: 228158

URL: https://gcc.gnu.org/viewcvs?rev=228158&root=gcc&view=rev
Log:
2015-09-25  Steven G. Kargl  <kargl@gcc.gnu.org>

        PR fortran/67614
        * resolve.c (gfc_resolve_code): Prevent ICE for invalid EXPR_NULL.

2015-09-25  Steven G. Kargl  <kargl@gcc.gnu.org>

        PR fortran/67614
        * gfortran.dg/pr67614.f90: New test.

Added:
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr67614.f90
Modified:
    branches/gcc-5-branch/gcc/fortran/ChangeLog
    branches/gcc-5-branch/gcc/fortran/resolve.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog


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

* [Bug fortran/67614] ICE on using arithmetic if with null
  2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
                   ` (6 preceding siblings ...)
  2015-09-25 22:59 ` kargl at gcc dot gnu.org
@ 2015-09-25 23:03 ` kargl at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2015-09-25 23:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |kargl at gcc dot gnu.org
   Target Milestone|---                         |5.3

--- Comment #8 from kargl at gcc dot gnu.org ---
Fixed on trunk and 5-branch.  Thanks for bug report
and convincing me to look at it again.


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

end of thread, other threads:[~2015-09-25 23:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-17 18:03 [Bug fortran/67614] New: ICE on using arithmetic if with null gerhard.steinmetz.fortran@t-online.de
2015-09-17 18:04 ` [Bug fortran/67614] " gerhard.steinmetz.fortran@t-online.de
2015-09-17 23:03 ` dominiq at lps dot ens.fr
2015-09-23 23:06 ` kargl at gcc dot gnu.org
2015-09-24 14:38 ` gerhard.steinmetz.fortran@t-online.de
2015-09-24 14:40 ` gerhard.steinmetz.fortran@t-online.de
2015-09-25 22:31 ` kargl at gcc dot gnu.org
2015-09-25 22:59 ` kargl at gcc dot gnu.org
2015-09-25 23:03 ` kargl 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).