Bug 46809 - [OOP] ICE with -fcheck=pointer for CLASS IS
Summary: [OOP] ICE with -fcheck=pointer for CLASS IS
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-12-05 13:28 UTC by Salvatore Filippone
Modified: 2010-12-12 21:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-12-07 20:33:35


Attachments
test case (767 bytes, text/plain)
2010-12-05 13:30 UTC, Salvatore Filippone
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Salvatore Filippone 2010-12-05 13:28:13 UTC

    
Comment 1 Salvatore Filippone 2010-12-05 13:29:12 UTC
With trunk at r167453 I get 

[sfilippo@localhost bug27]$ gfortran -v 
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/gnu46/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/usr/local/gnu46 --enable-languages=c,c++,fortran --with-gmp=/home/travel/GCC/gmp --with-mpfr=/home/travel/GCC/mpfr --with-mpc=/home/travel/GCC/mpc : (reconfigured) ../gcc/configure --prefix=/usr/local/gnu46 --with-gmp=/home/travel/GCC/gmp --with-mpfr=/home/travel/GCC/mpfr --with-mpc=/home/travel/GCC/mpc --enable-languages=c,c++,fortran,lto --no-create --no-recursion : (reconfigured) ../gcc/configure --prefix=/usr/local/gnu46 --with-gmp=/home/travel/GCC/gmp --with-mpfr=/home/travel/GCC/mpfr --with-mpc=/home/travel/GCC/mpc --enable-languages=c,c++,fortran,lto --no-create --no-recursion : (reconfigured) ../gcc/configure --prefix=/usr/local/gnu46 --with-gmp=/home/travel/GCC/gmp --with-mpfr=/home/travel/GCC/mpfr --with-mpc=/home/travel/GCC/mpc --enable-languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
gcc version 4.6.0 20101204 (experimental) (GCC) 
[sfilippo@localhost bug27]$ gfortran -fcheck=all -c psb_s_base_mat_impl.f03 
psb_s_base_mat_impl.f03: In function 'psb_s_base_transp_2mat':
psb_s_base_mat_impl.f03:120:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 2 Salvatore Filippone 2010-12-05 13:30:41 UTC
Created attachment 22642 [details]
test case

As usual, quite reduced from the original, but not necessarily minimal.
Comment 3 Dominique d'Humieres 2010-12-05 13:56:38 UTC
Confirmed as a regression between r162456 and r166102. GDB gives

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
trans_runtime_error_vararg (error=1 '\001', where=0x141947e30, msgid=0x141941ba0 "Pointer actual argument 'b' is not associated", ap=0x7fff5fbfcbb8) at ../../work/gcc/fortran/trans.c:400
400	      line = LOCATION_LINE (where->lb->location);
(gdb) bt
#0  trans_runtime_error_vararg (error=1 '\001', where=0x141947e30, msgid=0x141941ba0 "Pointer actual argument 'b' is not associated", ap=0x7fff5fbfcbb8) at ../../work/gcc/fortran/trans.c:400
#1  0x00000001000ad9d8 in gfc_trans_runtime_check (error=1 '\001', once=0 '\0', cond=0x142818e38, pblock=0x7fff5fbfd320, where=0x141947e30, msgid=0x141941ba0 "Pointer actual argument 'b' is not associated") at ../../work/gcc/fortran/trans.c:486
(gdb) p where->lb          
$2 = (gfc_linebuf *) 0x0
Comment 4 Tobias Burnus 2010-12-06 07:50:28 UTC
The relevant option is the check  -fcheck=pointer (I have thus updated the summary).

Valgrind shows:

==32004== Invalid read of size 4
==32004==    at 0x53F289: trans_runtime_error_vararg (trans.c:400)
==32004==    by 0x53FD4B: gfc_trans_runtime_check (trans.c:486)
==32004==    by 0x55C2A5: gfc_conv_procedure_call (trans-expr.c:3276)
==32004==    by 0x56A33C: gfc_conv_intrinsic_funcall (trans-intrinsic.c:1844)
==32004==    by 0x56E5B2: gfc_conv_intrinsic_function (trans-intrinsic.c:6156)
==32004==    by 0x55D849: gfc_conv_function_expr (trans-expr.c:3969)


The ICE happens for:
  if (where)
      line = LOCATION_LINE (where->lb->location);

Shorter example:
  module m
    type t
    end type t
  contains
    subroutine sub(a)
      class(t) :: a
      select type (a)
        class is (t)
          print *, 'Hi there'
      end select
    end subroutine
  end

The issue seems to be the EXTENDS_TYPE_OF call which is generated for CLASS IS; the call seems to have an "expr->where" defined - but not a where->lb->location.
Comment 5 janus 2010-12-07 20:33:35 UTC
(In reply to comment #4)
> The issue seems to be the EXTENDS_TYPE_OF call which is generated for CLASS IS;
> the call seems to have an "expr->where" defined - but not a
> where->lb->location.

We fail to set the location of the first argument when generating the EXTENDS_TYPE_OF call. The following patch fixes it:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 167369)
+++ gcc/fortran/resolve.c	(working copy)
@@ -7892,6 +7892,7 @@ resolve_select_type (gfc_code *code, gfc_namespace
 	  /* Set up arguments.  */
 	  new_st->expr1->value.function.actual = gfc_get_actual_arglist ();
 	  new_st->expr1->value.function.actual->expr = gfc_get_variable_expr (code->expr1->symtree);
+	  new_st->expr1->value.function.actual->expr->where = code->loc;
 	  gfc_add_vptr_component (new_st->expr1->value.function.actual->expr);
 	  vtab = gfc_find_derived_vtab (body->ext.case_list->ts.u.derived);
 	  st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
Comment 6 janus 2010-12-12 21:14:16 UTC
Author: janus
Date: Sun Dec 12 21:14:13 2010
New Revision: 167731

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167731
Log:
2010-12-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46809
	* resolve.c (resolve_select_type): Set the location of the first
	argument when generating the EXTENDS_TYPE_OF call.

2010-12-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46809
	* gfortran.dg/pointer_check_8.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/pointer_check_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2010-12-12 21:30:34 UTC
Fixed with r167731. Closing.