Bug 30190 - [4.1 only] Bounds check generates wrong code for associated(p1(i)%p2,p1(i)%p2)
Summary: [4.1 only] Bounds check generates wrong code for associated(p1(i)%p2,p1(i)%p2)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks: 29975
  Show dependency treegraph
 
Reported: 2006-12-12 22:50 UTC by Tobias Burnus
Modified: 2007-01-10 18:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-20 14:16:32


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2006-12-12 22:50:39 UTC
The following program crashes with -fbounds-check;
if one replaces the the "t(i)" by "t(1)" it works.

In associated.c, GFC_DESCRIPTOR_DATA(target) is ok, but for
GFC_DESCRIPTOR_DATA(pointer), one gets a memory access error.

----------------
  TYPE particle_type
     INTEGER, POINTER :: p(:)
  END TYPE particle_type
  TYPE(particle_type), POINTER  :: t(:)
  integer :: i
  i = 1
  allocate(t(1))
  allocate(t(1)%p(0))
  print *, associated(t(i)%p,t(i)%p)
end
----------------

Note 1: In the example, I used the same pointer for "target" and "pointer", but the same problem occurs, if they are different.

Note 2: Found by running CP2K with -fbounds-option. There it associated() is used in deallocate_particle_set().
Comment 1 Tobias Burnus 2006-12-12 22:59:24 UTC
If I dump the original tree, I find:
{ ...
int8 D.1351;
int8 D.1350;
int8 D.1349;
D.1351 = (int8) i; 
if( ... (t.dim[0].lbound > D.1351, 0)) ...
if( ... (t.dim[0].ubound < D.1351, 0)) ...
D.1352 = _gfortran_associated(...[t.dim[0].stride * D.1350 + t.offset].p,
  ...[t.dim[0].stride * D.1351 + t.offset].p)
    && ([t.dim[0].stride * D.1349 + t.offset].p.dim[0].stride != 0;
}

Question: What values have D.1350 and D.1349?
Comment 2 Paul Thomas 2006-12-20 14:16:32 UTC
The patch will be submitted, as soon as it has regtested.

Paul
Comment 3 patchapp@dberlin.org 2006-12-20 15:01:07 UTC
Subject: Bug number PR30190

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg01444.html
Comment 4 Paul Thomas 2006-12-20 21:11:04 UTC
Subject: Bug 30190

Author: pault
Date: Wed Dec 20 21:10:51 2006
New Revision: 120084

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120084
Log:
2006-12-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30190
	* trans-array.c (gfc_conv_array_ref): Remove gfc_evaluate_now
	from the -fbounds-check branch.

2006-12-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30190
	* gfortran.dg/bounds_check_5.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2006-12-31 15:00:55 UTC
Subject: Bug 30190

Author: pault
Date: Sun Dec 31 15:00:18 2006
New Revision: 120298

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120298
Log:
2006-12-31  Paul Thomas <pault@gcc.gnu.org>

	BACKPORTS from 4.3

	PR fortran/30202
	* trans-array.c (gfc_conv_function_call): Use parmse.expr for
	the nullifying of intent(out) arguments rather than the backend
	declaration.

	PR fortran/30190
	* trans-array.c (gfc_conv_array_ref): Remove gfc_evaluate_now
	from the -fbounds-check branch.

	PR fortran/29992
	* interface.c (check_sym_interfaces): Module procedures in a
	generic must be use associated or contained in the module.
	* decl.c (gfc_match_modproc): Set attribute mod_proc.
	* gfortran.h (symbol_attribute): Add mod_proc atribute.

	PR fortran/30081
	* resolve.c (resolve_generic_f, resolve_generic_s): Use
	gfc_intrinsic_name to find out if the function is intrinsic
	because it does not have to be a generic intrinsic to be
	overloaded.

	PR fortran/30236
	* interface.c (compare_interfaces): Handle NULL symbols.
	(count_types_test): Count NULL symbols, which correspond to
	alternate returns.

	(check_interface1): Change final argument from int to bool
	in the function and all references.

2006-12-31  Paul Thomas <pault@gcc.gnu.org>

	BACKPORTS from 4.3

	PR fortran/30202
	* gfortran.dg/alloc_comp_basics_3.f90: New test.

	PR fortran/30190
	* gfortran.dg/bounds_check_5.f90: New test.

	PR fortran/29992
	* gfortran.dg/generic_9.f90: New test.

	PR fortran/30081
	* gfortran.dg/generic_10.f90: New test.

	PR fortran/30236
	* gfortran.dg/altreturn_3.f90: New test.

	* gfortran.dg/char_result_12.f90: Fix comment typos.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/alloc_comp_basics_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/bounds_check_5.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_10.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_9.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/decl.c
    branches/gcc-4_2-branch/gcc/fortran/gfortran.h
    branches/gcc-4_2-branch/gcc/fortran/interface.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-array.c
    branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 6 Paul Thomas 2006-12-31 15:18:31 UTC
Fixed on trunk and 4.2

Paul