Bug 35150 - ICE in expand_expr_addr_expr_1, at expr.c:6728 (regression vs. earlier 4.3)
Summary: ICE in expand_expr_addr_expr_1, at expr.c:6728 (regression vs. earlier 4.3)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: 4.3.0
Assignee: Francois-Xavier Coudert
URL: http://gcc.gnu.org/ml/fortran/2008-02...
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2008-02-09 19:38 UTC by Tobias Burnus
Modified: 2008-02-15 21:15 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.3.0
Last reconfirmed: 2008-02-15 16:21:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-02-09 19:38:20 UTC
Working: 2007-07-16-r126671
Failing: 2007-07-19-r126744

Compiling F03GL (http://www-stone.ch.cam.ac.uk/pub/f03gl/, http://www-stone.ch.cam.ac.uk/pub/f03gl/f03gl.zip) gives the ICE:

gfortran  -fno-range-check -DNAGF95 -DOPENGL -c OpenGL_glut.f90
[...]
OpenGL_glut.f90: In function 'glutinit_f03':
OpenGL_glut.f90:1518: internal compiler error: in expand_expr_addr_expr_1, at expr.c:6835


Test case:

MODULE OpenGL_glut
  USE, INTRINSIC :: ISO_C_BINDING
  IMPLICIT NONE
CONTAINS
  SUBROUTINE glutInit_gl(pargc, argv) BIND(C,NAME="glutInit")
    INTEGER(C_INT) :: pargc
    TYPE(C_PTR), INTENT(IN) :: argv
  END SUBROUTINE glutInit_gl
  SUBROUTINE glutInit_f03()
    INTEGER(C_INT) :: argcp=1
    TYPE(C_PTR), DIMENSION(1), TARGET :: argv=C_NULL_PTR
    CHARACTER(C_CHAR), DIMENSION(1), TARGET :: empty_string=C_NULL_CHAR
    CALL glutInit_gl(argcp, C_LOC(argv))
  END SUBROUTINE
END MODULE OpenGL_glut
Comment 1 Tobias Burnus 2008-02-09 19:40:20 UTC
Possible cause for the regression:

r126744 | burnus | 2007-07-19 08:14:19 +0200 (Thu, 19 Jul 2007) | 14 lines
2007-07-19  Christopher D. Rickett  <crickett@lanl.gov>
        PR fortran/32600
        * trans-expr.c (gfc_conv_function_call): Inline C_LOC.

2007-07-19  Christopher D. Rickett  <crickett@lanl.gov>
        PR fortran/32600
        * libgfortran/intrinsics/iso_c_binding.c: Remove C_LOC.
        * libgfortran/intrinsics/iso_c_binding.h: Ditto.
        * libgfortran/gfortran.map: Ditto.
Comment 2 Andrew Pinski 2008-02-09 20:33:40 UTC
How is this a regression?  ISO_C_BINDING is new for 4.3.0 :).
Comment 3 Tobias Burnus 2008-02-09 22:02:35 UTC
> How is this a regression? ISO_C_BINDING is new for 4.3.0 :).

Well, it is not a regression versus 4.2, but it is nonetheless a regression: It was working before. How are such regressions marked?

 * * *

Simplified test case:

  USE ISO_C_BINDING
  TYPE(C_PTR), TARGET, SAVE :: argv
  INTERFACE
    SUBROUTINE glutInit_gl(argv) BIND(C)
      import
      TYPE(C_PTR) :: argv
    END SUBROUTINE glutInit_gl
  END INTERFACE
  CALL glutInit_gl(C_LOC(argv))
END


Dumped tree:

MAIN__ ()
{
  static void * argv;
  static integer(kind=4) options.0[7] = {68, 127, 0, 0, 0, 1, 0};

  _gfortran_set_options (7, (void *) &options.0);
  {
    static void * * C.906 = &argv;

    glutinit_gl (&C.906);
  }
}
Comment 4 Tobias Burnus 2008-02-09 22:04:28 UTC
Forget to write that the ICE is gone if one removed the SAVE
Comment 5 Francois-Xavier Coudert 2008-02-14 12:42:39 UTC
I've posted a workaround patch at http://gcc.gnu.org/ml/fortran/2008-02/msg00092.html. My analysis is currently as follow: we currently have

    static void * * C.906 = &argv;
    glutinit_gl (&C.906);

which leads to the ICE in expand_expr_addr_expr_1(). The code we emitted before, when C_LOC wasn't inlined, was:

    void * C.906 = _gfortran_c_loc (&argv);
    glutinit_gl (&C.906);

where _gfortran_c_loc was effectively:

    void * _gfortran_c_loc (void *p) { return p; }

As Tobias shown, the code taking care of taking the adress of argv (constructing "&argv") is in function gfc_conv_function_call (in trans-expr.c). I have tried to modify it by forcing a cast to pvoid_type_node, but it still gets the "static" attribute later. The variable creation is not done in that function, but later (and I cannot see why). If someone knows where, that would be great.

PS: I think that translating the ISO_C_BINDING inlined functions in gfc_conv_function_call() is actually too late. The intrinsic functions, for example, are intercepted somewhere earlier in the code path, and I think that would be better to do it in a similar way for intrinsic module functions (now, ISO_C_BINDING, and later, IEEE_*).
Comment 6 Tobias Burnus 2008-02-15 15:24:43 UTC
(In reply to comment #3)
> Simplified test case:
This now works with FX's patch.

However, using F03GL still fails with:
OpenGL_glut.f90: In function ‘glutinit_f03’:
OpenGL_glut.f90:1518: internal compiler error: in expand_expr_addr_expr_1, at expr.c:6835

For a reduced test case see comment 0. For that test case, one has the dump:

glutinit_f03 ()
{
  static integer(kind=4) argcp = 1;
  static void * argv[1] = {0};
  {
    static void *[1] * C.910 = &argv;
    glutinit_gl (&argcp, &C.910);
  }
}

That is, the ELSE branch needs to be fixed as well; the fix was only for rank == 0.
Comment 7 Francois-Xavier Coudert 2008-02-15 16:21:02 UTC
(In reply to comment #6)
> That is, the ELSE branch needs to be fixed as well; the fix was only for rank
> == 0.

OK, here is an updated patch:

Index: trans-expr.c
===================================================================
--- trans-expr.c        (revision 132257)
+++ trans-expr.c        (working copy)
@@ -2264,6 +2264,13 @@
              gfc_conv_array_parameter (se, arg->expr, argss, f);
            }
 
+         /* TODO -- the following two lines shouldn't be necessary, but
+            they're removed a bug is exposed later in the codepath.
+            This is workaround was thus introduced, but will have to be
+            removed; please see PR 35150 for details about the issue.  */
+         se->expr = convert (pvoid_type_node, se->expr);
+         se->expr = gfc_evaluate_now (se->expr, &se->pre);
+
          return 0;
        }
       else if (sym->intmod_sym_id == ISOCBINDING_FUNLOC)


I've started regtesting and will submit it for review afterwards.
Comment 8 Francois-Xavier Coudert 2008-02-15 21:15:06 UTC
Fixed on trunk:

Author: fxcoudert
Date: Fri Feb 15 21:12:24 2008
New Revision: 132353

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132353
Log:
	* trans-expr.c (gfc_conv_function_call): Force evaluation of
	se->expr.

	* gfortran.dg/c_loc_tests_12.f03: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/c_loc_tests_12.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog