This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: make check: Regressions on trunk and 4.2


Hi,

Tobias Burnus schrieb:
> Line 744 of gcc-4_2-branch/gcc/fortran/decl.c is function
> gfc_set_constant_character_len:
>
>       gfc_free (expr->value.character.string);
>
> This looks good in principle and also matches 4.3. Any ideas what goes
> wrong here?
>   
I think the reason I get the crash and others don't is because I use the
settings with glibc:
# fill new malloc areas with 0x42
export MALLOC_PERTURB_=B
# Abort on any malloc related error.
export MALLOC_CHECK_=2



I did debug it with gdb and I completely don't understand what goes
wrong here. Any idea?

(gdb) b gfc_set_constant_character_len
Breakpoint 3 at 0x413f60: file
/home/tob/projects/gcc-4_2-branch/gcc/fortran/decl.c, line 729.
(gdb) run
/home/tob/projects/gcc-4_2-branch/gcc/testsuite/gfortran.dg/constant_substring.f
[...]
2, expr=0xcb77c0) at
/home/tob/projects/gcc-4_2-branch/gcc/fortran/decl.c:729
729     {
(gdb) continue
Continuing.

Breakpoint 3, gfc_set_constant_character_len (len= [...]
4, expr=0xcbfef0) at
/home/tob/projects/gcc-4_2-branch/gcc/fortran/decl.c:729
729     {
(gdb) next
733       gcc_assert (expr->expr_type == EXPR_CONSTANT);
(gdb) next
729     {
(gdb) next
733       gcc_assert (expr->expr_type == EXPR_CONSTANT);
(gdb) next
734       gcc_assert (expr->ts.type == BT_CHARACTER && expr->ts.kind == 1);
(gdb) next
736       slen = expr->value.character.length;
(gdb) next
737       if (len != slen)
(gdb) next
739           s = gfc_getmem (len + 1);
(gdb) next
740           memcpy (s, expr->value.character.string, MIN (len, slen));
(gdb) next
739           s = gfc_getmem (len + 1);
(gdb) next
740           memcpy (s, expr->value.character.string, MIN (len, slen));
(gdb) next
741           if (len > slen)
(gdb) next
742             memset (&s[slen], ' ', len - slen);
(gdb) next
744           gfc_free (expr->value.character.string);
(gdb) next
743           s[len] = '\0';
(gdb) next
744           gfc_free (expr->value.character.string);
(gdb) next

Program received signal SIGABRT, Aborted.

Why do these two lines appear twice:
739           s = gfc_getmem (len + 1);
740           memcpy (s, expr->value.character.string, MIN (len, slen));
and
744           gfc_free (expr->value.character.string);

(By the way: slen = 2, len = 4 and expr->value.character.string = "12")


valgrind shows the following result:

==17897== Invalid write of size 1
==17897==    at 0x41C154: gfc_simplify_expr (expr.c:1490)
==17897==    by 0x41CB79: gfc_match_init_expr (expr.c:1891)
==17897==    by 0x4140BD: gfc_match_parameter (decl.c:3778)
==17897==    by 0x43F862: match_word (parse.c:65)
==17897==    by 0x43FFB8: decode_statement (parse.c:254)
==17897==    by 0x4407FA: next_statement (parse.c:493)
==17897==    by 0x4425FB: parse_spec (parse.c:1869)
==17897==    by 0x442AC5: parse_progunit (parse.c:2870)
==17897==    by 0x442FEF: gfc_parse_file (parse.c:3206)
==17897==    by 0x46269D: gfc_be_parse_file (f95-lang.c:303)
==17897==    by 0x6D8DB2: toplev_main (toplev.c:1033)
==17897==    by 0x52BAAE3: (below main) (in /lib64/libc-2.5.so)
==17897==  Address 0x40C4C1B is 0 bytes after a block of size 3 alloc'd
==17897==    at 0x4C22889: malloc (in
/usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
==17897==    by 0x852967: xmalloc (xmalloc.c:147)
==17897==    by 0x438AA4: gfc_getmem (misc.c:40)
==17897==    by 0x41C12B: gfc_simplify_expr (expr.c:1488)
==17897==    by 0x41CB79: gfc_match_init_expr (expr.c:1891)
==17897==    by 0x4140BD: gfc_match_parameter (decl.c:3778)
==17897==    by 0x43F862: match_word (parse.c:65)
==17897==    by 0x43FFB8: decode_statement (parse.c:254)
==17897==    by 0x4407FA: next_statement (parse.c:493)
==17897==    by 0x4425FB: parse_spec (parse.c:1869)
==17897==    by 0x442AC5: parse_progunit (parse.c:2870)
==17897==    by 0x442FEF: gfc_parse_file (parse.c:3206)

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]