This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Tighten up checks for ASSIGN statement


I ran into this when looking into PR 18827: we accepted ASSIGN statements of
the form
  ASSIGN 1000 TO I
where I is an array of integers.  Actually, we allowed general expressions as
long as they're of type integer.

This patch tightens stuff up, the standard only allows a scalar-int-variable,
with the variable being of default kind and this is enforced by this patch. I
will add the attached testcase to the testsuite, patch below.

Bubblestrapped and tested on i686-pc-linux. OK?

- Tobi

2004-12-05  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	* resolve.c (resolve_code): Impose correct restrictions on ASSIGN
	statement.

Index: resolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.21
diff -u -p -r1.21 resolve.c
--- resolve.c   8 Nov 2004 14:56:39 -0000       1.21
+++ resolve.c   6 Dec 2004 00:10:28 -0000
@@ -3678,9 +3678,15 @@ resolve_code (gfc_code * code, gfc_names
           if (code->label->defined == ST_LABEL_UNKNOWN)
             gfc_error ("Label %d referenced at %L is never defined",
                        code->label->value, &code->label->where);
-          if (t == SUCCESS && code->expr->ts.type != BT_INTEGER)
-           gfc_error ("ASSIGN statement at %L requires an INTEGER "
-                      "variable", &code->expr->where);
+          if (t == SUCCESS
+             && (code->expr->expr_type != EXPR_VARIABLE
+                 || code->expr->symtree->n.sym->ts.type != BT_INTEGER
+                 || code->expr->symtree->n.sym->ts.kind
+                       != gfc_default_integer_kind
+                 || code->expr->symtree->n.sym->as != NULL))
+           gfc_error ("ASSIGN statement at %L requires a scalar "
+                      "INTEGER*%d variable",
+                      &code->expr->where, gfc_default_integer_kind);
          break;

        case EXEC_POINTER_ASSIGN:


! { dg-do compile }
! Options passed to avoid excess errors from obsolete warning
! { dg-options "-w" }
      integer*4 i(5)
      assign 1000 to i   ! { dg-error "scalar INTEGER" }
 1000 continue
      end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]