Bug 87782 - [9 Regression] runtime error: load of value 1818451807, which is not a valid value for type 'expr_t'
Summary: [9 Regression] runtime error: load of value 1818451807, which is not a valid ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 9.0
Assignee: Thomas Koenig
URL:
Keywords:
Depends on:
Blocks: ubsan
  Show dependency treegraph
 
Reported: 2018-10-29 08:11 UTC by Martin Liška
Modified: 2018-11-01 19:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-10-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2018-10-29 08:11:47 UTC
It's a recent regression I believe. Using ubsan compiler one can see:

$ UBSAN_OPTIONS=print_stacktrace=1 gcc /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/testsuite/gfortran.dg/deferred_character_23.f90
../../gcc/fortran/frontend-passes.c:660:46: runtime error: load of value 1818451807, which is not a valid value for type 'expr_t'
    #0 0xf0a979 in constant_string_length ../../gcc/fortran/frontend-passes.c:660
    #1 0xf0c907 in create_var ../../gcc/fortran/frontend-passes.c:823
    #2 0xf07b5c in realloc_string_callback ../../gcc/fortran/frontend-passes.c:299
    #3 0xf32069 in gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) ../../gcc/fortran/frontend-passes.c:5073
    #4 0xf149e2 in realloc_strings ../../gcc/fortran/frontend-passes.c:1517
    #5 0xf14b4c in realloc_strings ../../gcc/fortran/frontend-passes.c:1522
    #6 0xf0709f in gfc_run_passes(gfc_namespace*) ../../gcc/fortran/frontend-passes.c:179
    #7 0xbb8898 in gfc_resolve(gfc_namespace*) ../../gcc/fortran/resolve.c:16736
    #8 0xae429f in gfc_parse_file() ../../gcc/fortran/parse.c:6266
    #9 0xc59435 in gfc_be_parse_file ../../gcc/fortran/f95-lang.c:204
    #10 0x2444c25 in compile_file ../../gcc/toplev.c:455
    #11 0x244da89 in do_compile ../../gcc/toplev.c:2172
    #12 0x244e1cf in toplev::main(int, char**) ../../gcc/toplev.c:2307
    #13 0x4971b0e in main ../../gcc/main.c:39
    #14 0x7ffff608cfea in __libc_start_main ../csu/libc-start.c:308
    #15 0x8669a9 in _start (/home/marxin/bin/gcc2/lib/gcc/x86_64-pc-linux-gnu/9.0.0/f951+0x8669a9)
Comment 1 Dominique d'Humieres 2018-10-29 11:09:55 UTC
I see that at r265374.
Comment 2 Thomas Koenig 2018-11-01 18:56:00 UTC
Index: frontend-passes.c
===================================================================
--- frontend-passes.c   (Revision 265722)
+++ frontend-passes.c   (Arbeitskopie)
@@ -638,23 +638,27 @@ constant_string_length (gfc_expr *e)
        return gfc_copy_expr(length);
     }
 
-  /* Return length of substring, if constant. */
+  /* See if there is a substring. If it has a constant length, return
+     that and NULL otherwise.  */
   for (ref = e->ref; ref; ref = ref->next)
     {
-      if (ref->type == REF_SUBSTRING
-         && gfc_dep_difference (ref->u.ss.end, ref->u.ss.start, &value))
+      if (ref->type == REF_SUBSTRING)
        {
-         res = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind,
-                                      &e->where);
+         if (gfc_dep_difference (ref->u.ss.end, ref->u.ss.start, &value))
+           {
+             res = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind,
+                                          &e->where);
 
-         mpz_add_ui (res->value.integer, value, 1);
-         mpz_clear (value);
-         return res;
+             mpz_add_ui (res->value.integer, value, 1);
+             mpz_clear (value);
+             return res;
+           }
+         else
+           return NULL;
        }
     }
 
   /* Return length of char symbol, if constant.  */
-
   if (e->symtree && e->symtree->n.sym->ts.u.cl
       && e->symtree->n.sym->ts.u.cl->length
       && e->symtree->n.sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)
Comment 3 Thomas Koenig 2018-11-01 18:56:48 UTC
The patch fixes this - if we have a substring, we should not look
at the symbol length.
Comment 4 Thomas Koenig 2018-11-01 19:50:45 UTC
Author: tkoenig
Date: Thu Nov  1 19:50:14 2018
New Revision: 265730

URL: https://gcc.gnu.org/viewcvs?rev=265730&root=gcc&view=rev
Log:
2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/87782
	* frontend-passes.c (constant_string_length): If there is a
	substring with a length which cannot be reduced to a constant,
	return NULL.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/frontend-passes.c
Comment 5 Thomas Koenig 2018-11-01 19:51:17 UTC
Fixed on trunk, closing