re PR fortran/82372 (Rejects valid parenthesis)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 15 Oct 2017 12:00:29 +0000 (12:00 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 15 Oct 2017 12:00:29 +0000 (12:00 +0000)
2017-10-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/82372
* fortran/scanner.c (last_error_char):  New global variable.
(gfc_scanner_init_1): Set last_error_char to NULL.
(gfc_gobble_whitespace): If a character not printable or
not newline, issue an error.

2017-10-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/82372
* gfortran.dg/illegal_char.f90: New test.

From-SVN: r253768

gcc/fortran/ChangeLog
gcc/fortran/scanner.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/illegal_char.f90 [new file with mode: 0644]

index ba9621fc8d5aa4464da67dfdac0105c5741e3890..5b003d81a9922226131780144df660adc6652d43 100644 (file)
@@ -1,3 +1,11 @@
+2017-10-15  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/82372
+       * fortran/scanner.c (last_error_char):  New global variable.
+       (gfc_scanner_init_1): Set last_error_char to NULL.
+       (gfc_gobble_whitespace): If a character not printable or
+       not newline, issue an error.
+
 2017-10-13  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/81048
index 82f431da52799f1ce4d3fdd9c15ce88d58f2366c..49decfac52a0324bba396eaf2739bb716d9d9170 100644 (file)
@@ -80,6 +80,7 @@ static struct gfc_file_change
 size_t file_changes_cur, file_changes_count;
 size_t file_changes_allocated;
 
+static gfc_char_t *last_error_char;
 
 /* Functions dealing with our wide characters (gfc_char_t) and
    sequences of such characters.  */
@@ -269,6 +270,7 @@ gfc_scanner_init_1 (void)
   continue_line = 0;
 
   end_flag = 0;
+  last_error_char = NULL;
 }
 
 
@@ -1700,6 +1702,14 @@ gfc_gobble_whitespace (void)
     }
   while (gfc_is_whitespace (c));
 
+  if (!ISPRINT(c) && c != '\n' && last_error_char != gfc_current_locus.nextc)
+    {
+      char buf[20];
+      last_error_char = gfc_current_locus.nextc;
+      snprintf (buf, 20, "%2.2X", c);
+      gfc_error_now ("Invalid character 0x%s at %C", buf);
+    }
+
   gfc_current_locus = old_loc;
 }
 
index d88bfb7e63be29397098f02d84c5e9b149949674..d8436266a5bbd5d21ae91382bf9490c7dffc8c19 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-15  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/82372
+       * gfortran.dg/illegal_char.f90: New test.
+
 2017-10-14  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
            Michael Collison <michael.collison@arm.com>
 
diff --git a/gcc/testsuite/gfortran.dg/illegal_char.f90 b/gcc/testsuite/gfortran.dg/illegal_char.f90
new file mode 100644 (file)
index 0000000..597c7b9
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR 82372 - show hexcode of illegal, non-printable characters
+program main
+  tmp =È   1.0 ! { dg-error "Invalid character 0xC8" }
+  print *,tmp
+end