PATCH: DWARF2 signedness bug

Mark Mitchell mark@codesourcery.com
Sun Apr 16 21:00:00 GMT 2000


This change:

  Sun Mar 26 11:37:55 2000  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* config/mips/mips.h (BITS_PER_WORD, UNITS_PER_WORD): Cast to unsigned.

broke DWARF2 output on MIPS.  The reason is that dwarf2out.c did:

  #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD))

Since UNITS_PER_WORD was (effectively) 4U, DWARF_CIE_DATA_ALIGNMENT
was -4U, or 4294967292.  Then, later we have:

      register long offset;
      ...
      offset /= DWARF_CIE_DATA_ALIGNMENT;

Here, offset was -16.  So, we promote -16 to unsigned, giving
4294967280.  The division then yields 0, instead of the expected 4.

Kenner, in addition to looking at GET_MODE_SIZE, please check all uses
of UNITS_PER_WORD and BITS_PER_WORD to ensure that your change is
safe.  Any negations of GET_MODE_SIZE, UNITS_PER_WORD, etc., are
suspect, as are comparisons with possibly negative quantities, as are
arithmetic operations involving these values and possibly negative
quantities.  Thanks.

(The lesson here is that there are certainly non-negative quantities
that should never-the-less be given signed types in C.  I'm not sure
if these cases are in that set or not.)

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-04-16  Mark Mitchell  <mark@codesourcery.com>

	* dwarf2out.c (DWARF_CIE_DATA_ALIGNMENT): Adjust, now that
	UNITS_PER_WORD is unsigned.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.167
diff -c -p -r1.167 dwarf2out.c
*** dwarf2out.c	2000/03/29 18:32:04	1.167
--- dwarf2out.c	2000/04/17 03:37:45
*************** dw_fde_node;
*** 164,172 ****
  
  /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
  #ifdef STACK_GROWS_DOWNWARD
! #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
  #else
! #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
  #endif
  
  /* A pointer to the base of a table that contains frame description
--- 164,172 ----
  
  /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
  #ifdef STACK_GROWS_DOWNWARD
! #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
  #else
! #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
  #endif
  
  /* A pointer to the base of a table that contains frame description


More information about the Gcc-patches mailing list