]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/28526 ('end' is recognized as a variable incorrectly)
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 18 Sep 2006 20:19:50 +0000 (20:19 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 18 Sep 2006 20:19:50 +0000 (20:19 +0000)
2006-09-18 Paul Thomas <pault@gcc.gnu.org>

PR fortran/28526
* primary.c (match_variable): If the compiler is in a module
specification block, an interface block or a contains section,
reset host_flag to force the changed symbols mechanism.

PR fortran/29101
* trans-stmt.c (gfc_trans_character_select): Add the post block
for the expression to the main block, after the call to
select_string and the last label.

2006-09-18 Paul Thomas <pault@gcc.gnu.org>

PR fortran/28526
* gfortran.dg/keyword_symbol_1.f90: New test.

* gfortran.dg/spread_shape_1.f90: Add missing warning with
pedantic compilation option.

From-SVN: r117034

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/fortran/trans-stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/keyword_symbol_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/spread_shape_1.f90

index 04b8c8e79cadf1b68d4d6d3b7770250af086985c..44e1800a144046180f811018a4adca60b1e45d7e 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-18 Paul Thomas <pault@gcc.gnu.org>
+
+       PR fortran/28526
+       * primary.c (match_variable): If the compiler is in a module
+       specification block, an interface block or a contains section,
+       reset host_flag to force the changed symbols mechanism.
+
+       PR fortran/29101
+       * trans-stmt.c (gfc_trans_character_select): Add the post block
+       for the expression to the main block, after the call to
+       select_string and the last label.
+
 2006-09-18  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/29060
index 1428f4c84e4d73fe0c8d7c1827f9eee031a42feb..6f61ad749ea4396c2d790303426bb7f29a001d95 100644 (file)
@@ -2283,6 +2283,17 @@ match_variable (gfc_expr ** result, int equiv_flag, int host_flag)
   locus where;
   match m;
 
+  /* Since nothing has any business being an lvalue in a module
+     specification block, an interface block or a contains section,
+     we force the changed_symbols mechanism to work by setting
+     host_flag to 0. This prevents valid symbols that have the name
+     of keywords, such as 'end', being turned into variables by
+     failed matching to assignments for, eg., END INTERFACE.  */
+  if (gfc_current_state () == COMP_MODULE
+      || gfc_current_state () == COMP_INTERFACE
+      || gfc_current_state () == COMP_CONTAINS)
+    host_flag = 0;
+
   m = gfc_match_sym_tree (&st, host_flag);
   if (m != MATCH_YES)
     return m;
index 97cb747ee54cb8eef52a12c1c217489b6ce92cb0..841b4578203638b97eafcd53851b98815d723d65 100644 (file)
@@ -1475,6 +1475,8 @@ gfc_trans_character_select (gfc_code *code)
   if (n != 0)
     gfc_free (labels);
 
+  gfc_add_block_to_block (&block, &se.post);
+
   return gfc_finish_block (&block);
 }
 
index 3311a54ef7a8690183107a6a8eb79ac5e0828420..73889e02932051c7dae2d987ef7a0e4d64427ccb 100644 (file)
@@ -1,3 +1,11 @@
+2006-09-18 Paul Thomas <pault@gcc.gnu.org>
+
+       PR fortran/28526
+       * gfortran.dg/keyword_symbol_1.f90: New test.
+
+       * gfortran.dg/spread_shape_1.f90: Add missing warning with
+       pedantic compilation option.
+
 2006-09-18  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/29060
diff --git a/gcc/testsuite/gfortran.dg/keyword_symbol_1.f90 b/gcc/testsuite/gfortran.dg/keyword_symbol_1.f90
new file mode 100644 (file)
index 0000000..7195f25
--- /dev/null
@@ -0,0 +1,57 @@
+! ' dg-do compile }
+! This tests the fix for PR28526, in which a public interface named
+! 'end' would be treated as a variable because the matcher tried
+! 'END INTERFACE' as an assignment and left the symbol modified in
+! failing. The various pitfalls that were encountered in developing
+! the fix are checked here.
+!
+! Contributed by Paul Thomas  <pault@gcc.gnu.org>
+!
+module blahblah
+  public function, end
+
+! The original PR from Yusuke IGUCHI <iguchi@coral.t.u-tokyo.ac.jp>
+  interface end
+    module procedure foo1
+  end interface
+
+! A contribution to the PR from Tobias Schlueter  <tobi@gcc.gnu.org>
+  interface function
+     module procedure foo2 ! { dg-error "is neither function nor" }
+  end interface
+
+  interface function
+     module procedure foo3
+  end interface
+
+  interface
+    function foo4 ()
+      real foo4
+      x = 1.0          ! { dg-error "in INTERFACE" }
+    end function foo4
+  end interface
+
+  interface
+    x = 2.0            ! { dg-error "in INTERFACE block" }
+    function foo5 ()
+      real foo5
+    end function foo5
+  end interface
+
+  x = 3.0              ! { dg-error "in MODULE" }
+
+contains
+
+  subroutine foo1
+  end subroutine foo1
+
+  function foo2        ! { dg-error "Expected formal argument list" }
+    foo2 = 0           ! { dg-error "already been host associated" }
+  end function foo2    ! { dg-error "Expecting END MODULE" }
+
+  function foo3 ()
+    real foo3
+  end function foo3
+
+  x = 4.0              ! { dg-error "in CONTAINS section" }
+end module blahblah
index c9f96f3661e8d3ce78f62b5cbc9b526f9177cd02..bbef232cc135209821d0e4c120b9de4b67644ef3 100644 (file)
@@ -4,7 +4,7 @@
 !
 ! Contributed by Paul Thomas  <pault@gcc.gnu.org>
   real,dimension(:, :),pointer :: ptr
-  real,dimension(2, 2),parameter :: u = &
+  real,dimension(2, 2),parameter :: u = & ! { dg-warning "nonstandard" }
        reshape((/0.25, 0.5, 0.75, 1.00/),(/2,2/))
   allocate (ptr(2,2))