http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45044

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-08-30 
13:26:23 UTC ---
Simple patch to print also a warning if a smaller named common block follows a
larger one.

TODO: Print the location of the other COMMON block. One can recover the line
number via DECL_SOURCE_FILE and DECL_SOURCE_LINE, but one still lacks the
column and the source-line string (cf. gfc_linebuf).


--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -392,4 +392,10 @@ build_common_decl (gfc_common_head *com, tree union_type,
bool is_init)
       tree size = TYPE_SIZE_UNIT (union_type);
+
+      if (!tree_int_cst_equal (DECL_SIZE_UNIT (decl), size)
+                 && strcmp (com->name, BLANK_COMMON_NAME))
+       gfc_warning ("Named COMMON block '%s' at %L shall be of the "
+                    "same size", com->name, &com->where);
+
       if (tree_int_cst_lt (DECL_SIZE_UNIT (decl), size))
-        {
+       {
          /* Named common blocks of the same name shall be of the same size
@@ -397,5 +403,2 @@ build_common_decl (gfc_common_head *com, tree union_type,
bool is_init)
             blank common blocks may be of different sizes.  */
-         if (strcmp (com->name, BLANK_COMMON_NAME))
-           gfc_warning ("Named COMMON block '%s' at %L shall be of the "
-                        "same size", com->name, &com->where);
          DECL_SIZE (decl) = TYPE_SIZE (union_type);

Reply via email to