scanner.c (preprocessor_line): Only set current_file->line when errors have not been...
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Jul 2005 15:55:53 +0000 (17:55 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 Jul 2005 15:55:53 +0000 (17:55 +0200)
* scanner.c (preprocessor_line): Only set current_file->line when errors
have not been encountered.  Warn and don't crash if a file leave
preprocessor line has no corresponding entering line.  Formatting.

* gfortran.dg/badline.f: New test.

From-SVN: r101717

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

index 8b23d570e9cbd2a5b1599fb7030a2c69dd84d858..45ae28c327f6595ee08a32475792f4cca1f42ea9 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-07  Jakub Jelinek  <jakub@redhat.com>
+
+       * scanner.c (preprocessor_line): Only set current_file->line when errors
+       have not been encountered.  Warn and don't crash if a file leave
+       preprocessor line has no corresponding entering line.  Formatting.
+
 2005-07-07  Steven Bosscher  <stevenb@suse.de>
 
        * primary.c (match_hollerith_constant): Use int, not unsigned int,
index 5aaecdb2ed99e9e1e9ec6bc8b45239ea4dd8a54e..b2efd81cf8b5cf4f2dca4dcfc696de40638b17ef 100644 (file)
@@ -839,15 +839,13 @@ preprocessor_line (char *c)
 
   line = atoi (c);
 
-  /* Set new line number.  */
-  current_file->line = line;
-
-  c = strchr (c, ' '); 
+  c = strchr (c, ' ');
   if (c == NULL)
-    /* No file name given.  */
-    return;
-
-
+    {
+      /* No file name given.  Set new line number.  */
+      current_file->line = line;
+      return;
+    }
 
   /* Skip spaces.  */
   while (*c == ' ' || *c == '\t')
@@ -880,7 +878,7 @@ preprocessor_line (char *c)
 
 
   /* Get flags.  */
-  
+
   flag[1] = flag[2] = flag[3] = flag[4] = flag[5] = false;
 
   for (;;)
@@ -895,24 +893,32 @@ preprocessor_line (char *c)
       if (1 <= i && i <= 4)
        flag[i] = true;
     }
-     
+
   /* Interpret flags.  */
-  
+
   if (flag[1] || flag[3]) /* Starting new file.  */
     {
       f = get_file (filename, LC_RENAME);
       f->up = current_file;
       current_file = f;
     }
-  
+
   if (flag[2]) /* Ending current file.  */
     {
-      current_file = current_file->up;
+      if (strcmp (current_file->filename, filename) != 0)
+       {
+         gfc_warning_now ("%s:%d: file %s left but not entered",
+                          current_file->filename, current_file->line,
+                          filename);
+         return;
+       }
+      if (current_file->up)
+       current_file = current_file->up;
     }
-  
+
   /* The name of the file can be a temporary file produced by
      cpp. Replace the name if it is different.  */
-  
+
   if (strcmp (current_file->filename, filename) != 0)
     {
       gfc_free (current_file->filename);
@@ -920,10 +926,12 @@ preprocessor_line (char *c)
       strcpy (current_file->filename, filename);
     }
 
+  /* Set new line number.  */
+  current_file->line = line;
   return;
 
  bad_cpp_line:
-  gfc_warning_now ("%s:%d: Illegal preprocessor directive", 
+  gfc_warning_now ("%s:%d: Illegal preprocessor directive",
                   current_file->filename, current_file->line);
   current_file->line++;
 }
index 57e7e08f945d2b481ac43c12c7be9752a2fb1ee5..36a93cd17c1a29fc80659c5ab36b36d350d117e1 100644 (file)
@@ -1,3 +1,7 @@
+2005-07-07  Jakub Jelinek  <jakub@redhat.com>
+
+       * gfortran.dg/badline.f: New test.
+
 2005-07-07  Feng Wang  <fengwang@nudt.edu.cn>
 
        PR fortran/16531
diff --git a/gcc/testsuite/gfortran.dg/badline.f b/gcc/testsuite/gfortran.dg/badline.f
new file mode 100644 (file)
index 0000000..9787ecd
--- /dev/null
@@ -0,0 +1,4 @@
+       subroutine foo 
+# 18 "src/badline.F" 2
+       end
+! { dg-warning "left but not entered" "" { target *-*-* } 2 }