Bug 87764 - gfortran crashes with illegal code
Summary: gfortran crashes with illegal code
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-10-26 17:41 UTC by Matthias Klose
Modified: 2021-12-26 10:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 12.0, 4.9.4
Last reconfirmed: 2021-12-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2018-10-26 17:41:24 UTC
seen on all active versions (test file ends with two newlines):

$ cat test.f90
end program &

$ /usr/lib/gcc-snapshot/bin/gfortran test.f90
f951: Warning: No location in statement
f951: internal compiler error: Segmentation fault
0x7f3381724fbf ???
        /build/glibc-hBZSf0/glibc-2.27/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7f3381711b16 __libc_start_main
        ../csu/libc-start.c:310
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
Comment 1 Dominique d'Humieres 2018-11-03 11:43:45 UTC
Confirmed from 4.8 up to trunk (9.0). An instrumented compiler gives

f951: Warning: No location in statement
../../work/gcc/fortran/trans.c:1768:39: runtime error: member access within null pointer of type 'struct gfc_linebuf'
f951: internal compiler error: Segmentation fault: 11
Comment 2 Harald Anlauf 2018-12-12 22:02:40 UTC
(In reply to Dominique d'Humieres from comment #1)
> Confirmed from 4.8 up to trunk (9.0). An instrumented compiler gives
> 
> f951: Warning: No location in statement
> ../../work/gcc/fortran/trans.c:1768:39: runtime error: member access within
> null pointer of type 'struct gfc_linebuf'
> f951: internal compiler error: Segmentation fault: 11

The warning in comment#0 would be restored by the patch:

Index: gcc/fortran/trans.c
===================================================================
--- gcc/fortran/trans.c (revision 267065)
+++ gcc/fortran/trans.c (working copy)
@@ -1765,8 +1765,11 @@
 void
 gfc_set_backend_locus (locus * loc)
 {
-  gfc_current_backend_file = loc->lb->file;
-  input_location = loc->lb->location;
+  if (loc->lb)
+    {
+      gfc_current_backend_file = loc->lb->file;
+      input_location = loc->lb->location;
+    }
 }

However, this papers over the issue that the locus is not properly set.