[PRs fortran/82972, fortran/83088, fortran/85851] Fix ICE with -finit-derived when using iso_c_binding

Fritz Reese fritzoreese@gmail.com
Fri Jun 22 20:46:00 GMT 2018


All,

The attached patch generates special initializers for derived-type
c_ptr and c_funptr symbols so they are handled correctly by the
translation phase. Previously, an EXPR_STRUCTURE expression was
generated for both types, as c_ptr and c_funptr are structure types
with a c_address field. The c_address field never had its backend_decl
generated, because it is typically handled specially.

With the patch, the trunk compiler does not exhibit the bugs in the
mentioned PRs (82972, 83088, 85851). I did encounter some issues
building and regression testing the trunk compiler which I am certain
are unrelated. The current trunk fails to bootstrap for me so I am
using an older revision which appears to have some testcase issues.
The issues are attached at the bottom of this e-mail for reference.

In any case, the changelog is here, and the patch is attached. Aside
from the issues mentioned below the compile bootstraps and regression
tests successfully. Does this look OK for trunk? Furthermore, this
patch comes a bit late as the PRs were submitted before 8.1 was
released; is it appropriate to backport this to 7-branch and/or
8-branch?


>From b6fbe8e429d5c98675741234e2ac5cc6810df3c5 Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Fri, 22 Jun 2018 16:11:02 -0400
Subject: [PATCH] PR fortran/82972

Fix -finit-derived for c_ptr and c_funptr in programs which use iso_c_binding.

gcc/fortran/
    * expr.c (component_initializer): Assign init expr to c->initializer.
    (generate_isocbinding_initializer): New.
    (gfc_generate_initializer): Call generate_isocbinding_initializer to
    generate initializers for c_ptr and c_funptr with -finit-derived.

gcc/testsuite/
    * gfortran.dg/init_flag_17.f90: New testcase.
---
 gcc/fortran/expr.c                         | 33 +++++++++++++++++++++++++++++-
 gcc/testsuite/gfortran.dg/init_flag_17.f90 | 28 +++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/init_flag_17.f90


======= TEST ISSUES =======


$ gfortran --version
GNU Fortran (GCC) 8.0.0 20180110 (experimental)
...
$ make -sk check-fortran
...
FAIL: gfortran.dg/pr68078.f90   -O0  execution test
FAIL: gfortran.fortran-torture/compile/pr83081.f90,  -O3 -g
(internal compiler error)
...

In the first case (pr68078) the process appears to occasionally run
out of stack memory due to the setrlimit(), causing it to receive
SIGSEGV.

$ cd gcc/testsuite/gfortran.dg
$ gfortran pr68078.f90 set_vm_limit.c -o pr68078
$ i=0; time while ./a.out >/dev/null; do echo attempt $i; i=$(($i+1)) ; done
attempt 0
attempt 1
attempt 2
attempt 3
attempt 4
attempt 5
attempt 6
attempt 7
attempt 8
attempt 9
attempt 10
Segmentation fault (core dumped)

real    0m0.104s
user    0m0.007s
sys    0m0.023s

The second case appears positively unrelated (and only occurs with -O3):

$ gfortran -c -O3 pr83081.f90
during GIMPLE pass: pcom
pr83081.f90:4:0:

   Subroutine SPLIFT (X,Y,YP,YPP,N,IERR,ISX,A1,B1,AN,BN)

internal compiler error: in probability_in, at profile-count.h:1038
0x6f47ee profile_count::probability_in(profile_count) const
    /data/midas/foreese/src/gcc-trunk/gcc/profile-count.h:1038
0x6f47ee tree_transform_and_unroll_loop(loop*, unsigned int,
edge_def*, tree_niter_desc*, void (*)(loop*, void*), void*)
    /data/midas/foreese/src/gcc-trunk/gcc/tree-ssa-loop-manip.c:1382
0xe36716 tree_predictive_commoning_loop
    /data/midas/foreese/src/gcc-trunk/gcc/tree-predcom.c:3278
0xe37e7d tree_predictive_commoning()
    /data/midas/foreese/src/gcc-trunk/gcc/tree-predcom.c:3312
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.


======= END TEST ISSUES =======
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr82972.patch
Type: text/x-patch
Size: 3840 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180622/96ccd43a/attachment.bin>


More information about the Gcc-patches mailing list