[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-11 Thread fxcoudert at gcc dot gnu dot org


--- Comment #7 from fxcoudert at gcc dot gnu dot org  2007-08-11 21:53 
---
Fixed.


-- 

fxcoudert at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-11 Thread fxcoudert at gcc dot gnu dot org


--- Comment #6 from fxcoudert at gcc dot gnu dot org  2007-08-11 21:31 
---
Subject: Bug 32937

Author: fxcoudert
Date: Sat Aug 11 21:31:35 2007
New Revision: 127363

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127363
Log:
PR fortran/32937

* trans-array.c (gfc_conv_expr_descriptor): Use
gfc_conv_const_charlen to generate backend_decl of right type.
* trans-expr.c (gfc_conv_expr_op): Use correct return type.
(gfc_build_compare_string): Use int type instead of default
integer kind for single character comparison.
(gfc_conv_aliased_arg): Give backend_decl the right type.
* trans-decl.c (gfc_build_intrinsic_function_decls): Make
compare_string return an int.

* gfortran.dg/char_length_6.f90: New test.

* intrinsics/string_intrinsics.c (compare_string): Return an int.
* libgfortran.h (compare_string): Likewise.

Added:
trunk/gcc/testsuite/gfortran.dg/char_length_6.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-array.c
trunk/gcc/fortran/trans-decl.c
trunk/gcc/fortran/trans-expr.c
trunk/gcc/testsuite/ChangeLog
trunk/libgfortran/ChangeLog
trunk/libgfortran/intrinsics/string_intrinsics.c
trunk/libgfortran/libgfortran.h


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-11 Thread fxcoudert at gcc dot gnu dot org


--- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-08-11 11:17 
---
Hurray! It's been my wildest gdb session since a very long time (two sessions
of two hours each), but I've made it at last! My analysis in the previous
comment was right, we are generating a charlen's backend_decl with a wrong
type, which is fixed by:

Index: trans-array.c
===
--- trans-array.c   (revision 127334)
+++ trans-array.c   (working copy)
@@ -4547,9 +4547,7 @@ gfc_conv_expr_descriptor (gfc_se * se, g
  else if (expr->ts.cl->length
 && expr->ts.cl->length->expr_type == EXPR_CONSTANT)
{
- expr->ts.cl->backend_decl
-   = gfc_conv_mpz_to_tree (expr->ts.cl->length->value.integer,
-   expr->ts.cl->length->ts.kind);
+ gfc_conv_const_charlen (expr->ts.cl);
  loop.temp_ss->data.temp.type
= gfc_typenode_for_spec (&expr->ts);
  loop.temp_ss->string_length

(we even have a function ready for that case, mind you). I'm regtesting, and
I'll commit as obvious shortly after.

/me goes for a shower and an afternoon far away from gdb


-- 

fxcoudert at gcc dot gnu dot org changed:

   What|Removed |Added

   Keywords||patch
   Target Milestone|--- |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-10 Thread fxcoudert at gcc dot gnu dot org


--- Comment #4 from fxcoudert at gcc dot gnu dot org  2007-08-10 15:31 
---
The problem with integer kind is from the string length:

  character(2_8) :: c(2)
  integer :: i

  c = "aa"
  print *, c .eq. "aa"
  call foo ((/(c(i), i = 1,2)/))
  print *, c .eq. "aa"

contains
  subroutine foo (c)
character(*), dimension(:) :: c
  end subroutine foo
end

If you compile it and set a breakpoint on the translation of the string
comparison (which is trans-expr.c:1172), and print out the tree that is the
length of c (lse.string_length), you get the first time:

  constant
invariant 2>
$3 = void

which is correct, while the second time you get:

  constant
invariant 2>

which is wrong: the charlen type is int4, not int8.  Somehow, the conjunction
of function call and temporary produces this, because if you remove either the
function call or the need for a temporary, the code is then correct.

>From what I seem there is a cl->backend_decl somewhere (or a string_length)
that is generated refering to this int8 constant, which should never happen. I
haven't been able to find out where this happens, though.



PS: in the mean time, I've found what I think is an unrelated bug. This is the
only occurrence that I could find of an cl->backend_decl with wrong type, but
it doesn't fix this bug  ;-)

Index: trans-expr.c
===
--- trans-expr.c(revision 127334)
+++ trans-expr.c(working copy)
@@ -1855,6 +1851,7 @@ gfc_conv_aliased_arg (gfc_se * parmse, g
gfc_array_index_type);
tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
   tmp, tmp_se.expr);
+   tmp = fold_convert (gfc_charlen_type_node, tmp);
expr->ts.cl->backend_decl = tmp;

break;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-10 Thread fxcoudert at gcc dot gnu dot org


--- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-08-10 12:34 
---
The further I can reduce this is:

$ cat u.f90
  character(2) :: c(2)
  integer(kind=4) :: i

  c = "aa"
  call foo ((/(c(i), i = 1_4,2_4)/))
  print *, c .eq. "aa"

contains
  subroutine foo (c)
character(*), dimension(:) :: c
  end subroutine foo
end
$ gfortran -m32 -fdefault-integer-8 u.f90 && ./a.out
Segmentation fault

The only place where integer default kind appears is the .eq. operator, which
returns a logical of the default kind.


-- 

fxcoudert at gcc dot gnu dot org changed:

   What|Removed |Added

 AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
   |dot org |org
 Status|NEW |ASSIGNED
   Last reconfirmed|2007-08-08 15:26:23 |2007-08-10 12:34:34
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-08-08 Thread fxcoudert at gcc dot gnu dot org


--- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-08-08 15:26 
---
Confirmed on x86_64-linux with -m32.


-- 

fxcoudert at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever Confirmed|0   |1
   Last reconfirmed|-00-00 00:00:00 |2007-08-08 15:26:23
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937



[Bug fortran/32937] segfault with string and -fdefault-integer-8

2007-07-30 Thread dominiq at lps dot ens dot fr


--- Comment #1 from dominiq at lps dot ens dot fr  2007-07-30 20:24 ---
> The problem appears to be that the first argument to gfortani_compare_string
> is pushed as an 8-byte integer, which messes things up.

The test passes for me with -m64, without it the backtrace is (on Darwin8):

Host Name:  pbook
Date/Time:  2007-07-30 22:16:50.772 +0200
OS Version: 10.4.10 (Build 8R218)
Report Version: 4

Command: a.out
Path:a.out
Parent:  tcsh [26848]

Version: ??? (???)

PID:115
Thread: 0

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:  KERN_PROTECTION_FAILURE (0x0002) at 0x0004

Thread 0 Crashed:
0   libSystem.B.dylib   0x90131280 bcmp + 224
1   libgfortran.3.dylib 0x00474acc _gfortran_compare_string + 64
(string_intrinsics.c:87)
2   a.out   0x3738 MAIN__ + 976 (darwin-crt3.c:395)
3   a.out   0x3b94 main + 48 (fmain.c:26)
4   a.out   0x28b0 _start + 760
5   a.out   0x25b4 start + 48

Thread 0 crashed with PPC Thread State 64:
  srr0: 0x90131280 srr1: 0x1000d030   
vrsave: 0x
cr: 0x44008002  xer: 0x2000   lr: 0x00474acc 
ctr: 0x0400
r0: 0x1000   r1: 0xbfffe230   r2: 0x001c  
r3: 0x0004
r4: 0x   r5: 0xbfffd2e4   r6: 0x  
r7: 0x
r8: 0x0400   r9: 0x1000  r10: 0x0006 
r11: 0x22008002
   r12: 0x901311a0  r13: 0x  r14: 0x 
r15: 0x
   r16: 0x  r17: 0x  r18: 0x 
r19: 0x
   r20: 0x  r21: 0x  r22: 0x 
r23: 0x
   r24: 0x  r25: 0x0001  r26: 0xbfffe5bc 
r27: 0x0004
   r28: 0x  r29: 0x  r30: 0xbfffe2e4 
r31: 0x3380

Binary Images Description:
0x1000 - 0x3fff a.out  
/Users/dominiq/Documents/Fortran/g95bench/win/f90/bug/a.out
   0x33000 -0x3efff libgcc_s.1.dylib   
/opt/gcc/gcc4.3/lib/libgcc_s.1.dylib
   0x7e000 -0x89fff libgcc_s.1.dylib/libgcc_s.1.dylib
  0x405000 -   0x481fff libgfortran.3.dylib
/opt/gcc/gcc4.3/lib/libgfortran.3.dylib
0x8fe0 - 0x8fe52fff dyld 46.12  /usr/lib/dyld
0x9000 - 0x901bcfff libSystem.B.dylib   /usr/lib/libSystem.B.dylib
0x90214000 - 0x90219fff libmathCommon.A.dylib  
/usr/lib/system/libmathCommon.A.dylib


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32937