From a48ebf39c9ff4310332dd9f2ea84f2992d7c9076 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Sat, 17 Nov 2007 00:10:00 +0000 Subject: [PATCH] re PR fortran/34108 (ICE: Segmentation fault occurs by "write(*,0)" statement) PR fortran/34108 * io.c (check_format_string): Only check character expressions. (match_dt_format): Return MATCH_ERROR if that is what gfc_match_st_label said. * gfortran.dg/fmt_label_1.f90: New test. From-SVN: r130249 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/io.c | 8 ++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/fmt_label_1.f90 | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/fmt_label_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a8896823169..0d343eb7128 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2007-11-17 Francois-Xavier Coudert + + PR fortran/34108 + * io.c (check_format_string): Only check character expressions. + (match_dt_format): Return MATCH_ERROR if that is what + gfc_match_st_label said. + 2007-11-16 Francois-Xavier Coudert PR fortran/33957 diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 0e2a0cb7df2..bb4295b866a 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -919,7 +919,7 @@ finished: static try check_format_string (gfc_expr *e, bool is_input) { - if (!e || e->expr_type != EXPR_CONSTANT) + if (!e || e->ts.type != BT_CHARACTER || e->expr_type != EXPR_CONSTANT) return SUCCESS; mode = MODE_STRING; @@ -2082,6 +2082,7 @@ match_dt_format (gfc_dt *dt) locus where; gfc_expr *e; gfc_st_label *label; + match m; where = gfc_current_locus; @@ -2094,7 +2095,7 @@ match_dt_format (gfc_dt *dt) return MATCH_YES; } - if (gfc_match_st_label (&label) == MATCH_YES) + if ((m = gfc_match_st_label (&label)) == MATCH_YES) { if (dt->format_expr != NULL || dt->format_label != NULL) { @@ -2108,6 +2109,9 @@ match_dt_format (gfc_dt *dt) dt->format_label = label; return MATCH_YES; } + else if (m == MATCH_ERROR) + /* The label was zero or too large. Emit the correct diagnosis. */ + return MATCH_ERROR; if (gfc_match_expr (&e) == MATCH_YES) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 21761526653..bec1ea53bcd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-11-17 Francois-Xavier Coudert + + PR fortran/34108 + * gfortran.dg/fmt_label_1.f90: New test. + 2007-11-16 Francois-Xavier Coudert PR fortran/33957 diff --git a/gcc/testsuite/gfortran.dg/fmt_label_1.f90 b/gcc/testsuite/gfortran.dg/fmt_label_1.f90 new file mode 100644 index 00000000000..eb11b790d2f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/fmt_label_1.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! +! Check for diagnostics (PR 34108) + write (*,0) 'xxx' ! { dg-error "Statement label .* is zero" } + write (*,1) 'xxx' ! { dg-error "FORMAT label .* not defined" } + write (*,123456) 'xxx' ! { dg-error "Too many digits in statement label" } + write (*,-1) 'xxx' ! { dg-error "" } + end -- 2.30.2