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]

[gfortran] Fix bug for size of COMMON block


2003-11-25  Canqun Yang  <canqun@nudt.edu.cn>

	* trans-common.c (gfc_layout_global_equiv): 
Locate the error for
	underflow COMMON block.
	(gfc_trans_one_common): Fix bug for size of 
COMMON block containing
	EQUIVALENCE object. Also fix typo in an error 
message.

! The size of common 'com1' should be 80, instead of 112.
program common_size
   real (kind=8) a(8)
   real (kind=8) b(5), c(5)
   common /com1/b,c
   equivalence (a(1), b(2))
   b = 100
   c = 200 
   if ((a (4) .ne. 100) .or. (a(5) .ne. 200)) call abort
end


*** trans-common.c	2003-11-13 18:08:24.000000000 +0800
--- trans-common.c	2003-11-25 14:58:28.000000000 +0800
*************** gfc_layout_global_equiv (gfc_symbol * co
*** 312,319 ****
  
        /* var_offset<0 means an underflow error for the master area.  */
        if (tree_int_cst_sgn (var_offset) == -1)
!          gfc_fatal_error ("COMMON '%s' underflow due to EQUIVALENCE.",
!                           common_sym->name);
  
        var_size = TYPE_SIZE_UNIT (gfc_sym_type (equiv_var));
  
--- 312,319 ----
  
        /* var_offset<0 means an underflow error for the master area.  */
        if (tree_int_cst_sgn (var_offset) == -1)
!          gfc_fatal_error ("COMMON '%s' at %L underflow due to EQUIVALENCE.",
!                           common_sym->name, &common_sym->declared_at);
  
        var_size = TYPE_SIZE_UNIT (gfc_sym_type (equiv_var));
  
*************** gfc_trans_one_common (gfc_common_type co
*** 348,353 ****
--- 348,354 ----
    tree common_decl;
    tree common_size;
    tree offset;
+   tree s;
  
    gfc_clear_ts (&ts);
    /* No COMMON variables in the COMMON block, do nothing.  */
*************** gfc_trans_one_common (gfc_common_type co
*** 369,376 ****
        var_size = TYPE_SIZE_UNIT (var_type);
  
        if (!INTEGER_CST_P (var_size))
!         gfc_error ("Size of common variable '%s' at %L must be const",
!                  var->name, &var->declared_at);
  
        /* Determine the master type of the COMMON block area.  */
        gfc_get_common_master_type (&ts, var);
--- 370,377 ----
        var_size = TYPE_SIZE_UNIT (var_type);
  
        if (!INTEGER_CST_P (var_size))
!         gfc_error ("Size of common variable '%s' at %L must be constant",
!                    var->name, &var->declared_at);
  
        /* Determine the master type of the COMMON block area.  */
        gfc_get_common_master_type (&ts, var);
*************** gfc_trans_one_common (gfc_common_type co
*** 393,400 ****
        var->addr_offset = offset;
  
        /* Current COMMON area size.  */
!       common_size = fold (build (PLUS_EXPR,
!                                  gfc_array_index_type, common_size, var_size));
  
        /* Layout global EQUIVALENCE objects.  */
        if (var->equiv_ring)
--- 394,402 ----
        var->addr_offset = offset;
  
        /* Current COMMON area size.  */
!       s = fold (build (PLUS_EXPR, gfc_array_index_type, offset, var_size));
!       if (tree_int_cst_lt (common_size, s))
!         common_size = s;
  
        /* Layout global EQUIVALENCE objects.  */
        if (var->equiv_ring)

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