re PR fortran/85088 (improve diagnostic for bad INTENT declaration ('Invalid characte...
authorJanus Weil <janus@gcc.gnu.org>
Sun, 10 Jun 2018 08:20:50 +0000 (10:20 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Sun, 10 Jun 2018 08:20:50 +0000 (10:20 +0200)
2018-06-10  Janus Weil  <janus@gcc.gnu.org>

PR fortran/85088
* decl.c (match_attr_spec): Synchronize the DECL_* enum values with the
INTENT_* values from the enum 'sym_intent'. Call 'match_intent_spec'
and remove a TODO note.
* gfortran.h: Add a comment to sym_intent.

2018-06-10  Janus Weil  <janus@gcc.gnu.org>

PR fortran/85088
* gfortran.dg/intent_decl_1.f90: New test case.

From-SVN: r261386

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/fortran/gfortran.h
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/intent_decl_1.f90 [new file with mode: 0644]

index 7bfeac1c8aa918a217383c4b1259d75afa220b33..3b22db13b146ce1d950c827ff5a182c08e19d35b 100644 (file)
@@ -1,3 +1,11 @@
+2018-06-10  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/85088
+       * decl.c (match_attr_spec): Synchronize the DECL_* enum values with the
+       INTENT_* values from the enum 'sym_intent'. Call 'match_intent_spec'
+       and remove a TODO note.
+       * gfortran.h: Add a comment to sym_intent.
+
 2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
  
        PR fortran/38351
index c36a16ba5ace239060e5b6be51a087dc297f61b1..707c2a74bbb0cd01244655b2d39c996095209070 100644 (file)
@@ -4726,9 +4726,10 @@ match_attr_spec (void)
 {
   /* Modifiers that can exist in a type statement.  */
   enum
-  { GFC_DECL_BEGIN = 0,
-    DECL_ALLOCATABLE = GFC_DECL_BEGIN, DECL_DIMENSION, DECL_EXTERNAL,
-    DECL_IN, DECL_OUT, DECL_INOUT, DECL_INTRINSIC, DECL_OPTIONAL,
+  { GFC_DECL_BEGIN = 0, DECL_ALLOCATABLE = GFC_DECL_BEGIN,
+    DECL_IN = INTENT_IN, DECL_OUT = INTENT_OUT, DECL_INOUT = INTENT_INOUT,
+    DECL_DIMENSION, DECL_EXTERNAL,
+    DECL_INTRINSIC, DECL_OPTIONAL,
     DECL_PARAMETER, DECL_POINTER, DECL_PROTECTED, DECL_PRIVATE,
     DECL_STATIC, DECL_AUTOMATIC,
     DECL_PUBLIC, DECL_SAVE, DECL_TARGET, DECL_VALUE, DECL_VOLATILE,
@@ -4739,6 +4740,9 @@ match_attr_spec (void)
 /* GFC_DECL_END is the sentinel, index starts at 0.  */
 #define NUM_DECL GFC_DECL_END
 
+  /* Make sure that values from sym_intent are safe to be used here.  */
+  gcc_assert (INTENT_IN > 0);
+
   locus start, seen_at[NUM_DECL];
   int seen[NUM_DECL];
   unsigned int d;
@@ -4856,13 +4860,12 @@ match_attr_spec (void)
                      if (match_string_p ("nt"))
                        {
                          /* Matched "intent".  */
-                         /* TODO: Call match_intent_spec from here.  */
-                         if (gfc_match (" ( in out )") == MATCH_YES)
-                           d = DECL_INOUT;
-                         else if (gfc_match (" ( in )") == MATCH_YES)
-                           d = DECL_IN;
-                         else if (gfc_match (" ( out )") == MATCH_YES)
-                           d = DECL_OUT;
+                         d = match_intent_spec ();
+                         if (d == INTENT_UNKNOWN)
+                           {
+                             m = MATCH_ERROR;
+                             goto cleanup;
+                           }
                        }
                    }
                  else if (ch == 'r')
index b7eaa0e35abdaa2b225998323ada1d518d7be383..113ed3c1e633d476f525337bbac40bfc2f7e149c 100644 (file)
@@ -291,7 +291,8 @@ enum procedure_type
   PROC_INTRINSIC, PROC_ST_FUNCTION, PROC_EXTERNAL
 };
 
-/* Intent types.  */
+/* Intent types. Note that these values are also used in another enum in
+   decl.c (match_attr_spec).  */
 enum sym_intent
 { INTENT_UNKNOWN = 0, INTENT_IN, INTENT_OUT, INTENT_INOUT
 };
index 05780742b56d3944defbf8759e44bf127d927ff3..8693372a3cf4db48f9cb460cae43f997f16e7560 100644 (file)
@@ -1,3 +1,9 @@
+
+2018-06-10  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/85088
+       * gfortran.dg/intent_decl_1.f90: New test case.
+
 2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        * gfortran.dg/ieee/ieee_4.f90: xfail on i?86-*-freebsd*
diff --git a/gcc/testsuite/gfortran.dg/intent_decl_1.f90 b/gcc/testsuite/gfortran.dg/intent_decl_1.f90
new file mode 100644 (file)
index 0000000..af848b8
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+!
+! PR 85088: improve diagnostic for bad INTENT declaration
+!
+! Contributed by Janus Weil <janus@gcc.gnu.org>
+
+subroutine s(x, y, z)
+   integer, intent(int) :: x  ! { dg-error "Bad INTENT specification" }
+   integer, intent :: y       ! { dg-error "Bad INTENT specification" }
+   integer, inten  :: z       ! { dg-error "Invalid character" }
+end