[4.2/4.3 Regression] Incorrect result with -O2

Paul Richard Thomas paul.richard.thomas@gmail.com
Thu Jun 14 04:48:00 GMT 2007


Paul,

The above PR is rather nasty because, although a warning is emitted,
it yields incorrect results when any level of optimization is applied.

The problem occurs when named common blocks have different sizes and
the patch of code in trans-common.c (build_common_decl) comes into
play.

  /* Update the size of this common block as needed.  */
  if (decl != NULL_TREE)
    {
      tree size = TYPE_SIZE_UNIT (union_type);
      if (tree_int_cst_lt (DECL_SIZE_UNIT (decl), size))
        {
          /* Named common blocks of the same name shall be of the same size
             in all scoping units of a program in which they appear, but
             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_UNIT (decl) = size;
        }
     }

There are half a dozen or more workarounds, all of which prevent this
resizing of the union/record type.

At present, I have been unable to reduce the testscase to understand
precisely what is going on.  All the testcases that I have written run
correctly, in spite of having similar differences in the mix of
default integer and double precision between the versions of the
common block.

I had thought that, since there was possibly an offset rounding-up
issue at stake, using relayout (decl) would deal with it.  However, I
was misled by leaving one of the workarounds in place.

I am completely stumped by this one - do you have any ideas or can you
advise who to ask?

Cheers

Paul


-- 
I love deadlines. I love the whooshing sound they make as they go by.
--Douglas Adams



More information about the Fortran mailing list