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]

Enum initialization modifies expression's type


The testcase in the attached patch failed because build_enumerator()
modified the type of the initializer, that was a constant obtained
from the size_table, and already referenced as TYPE_SIZE of the
`void*' type.  Then, when the size was given to size_binop(), it
didn't have the same type as the other argument, so we crashed.

This patch fixes this problem.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@cygnus.com>

	* c-decl.c (build_enumerator): Don't modify the value's type,
	convert it.

Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-decl.c,v
retrieving revision 1.247
diff -u -p -c -r1.247 c-decl.c
*** gcc/c-decl.c	2000/05/23 20:19:20	1.247
--- gcc/c-decl.c	2000/05/24 02:54:18
*************** build_enumerator (name, value)
*** 5688,5695 ****
  			 && TREE_UNSIGNED (type)));
  
    decl = build_decl (CONST_DECL, name, type);
!   DECL_INITIAL (decl) = value;
!   TREE_TYPE (value) = type;
    pushdecl (decl);
  
    return tree_cons (decl, value, NULL_TREE);
--- 5688,5694 ----
  			 && TREE_UNSIGNED (type)));
  
    decl = build_decl (CONST_DECL, name, type);
!   DECL_INITIAL (decl) = convert (type, value);
    pushdecl (decl);
  
    return tree_cons (decl, value, NULL_TREE);
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@cygnus.com>

	* gcc.c-torture/compile/20000523-1.c: New test.

Index: gcc/testsuite/gcc.c-torture/compile/20000523-1.c
===================================================================
RCS file: 20000523-1.c
diff -N 20000523-1.c
*** gcc/testsuite/gcc.c-torture/compile/20000523-1.c	Tue May  5 13:32:27 1998
--- gcc/testsuite/gcc.c-torture/compile/20000523-1.c	Tue May 23 19:54:19 2000
***************
*** 0 ****
--- 1,5 ----
+ /* Copyright (C) 2000  Free Software Foundation  */
+ /* Contributed by Alexandre Oliva <aoliva@cygnus.com> */
+ 
+ enum { foo = sizeof(void *) };
+ int i = sizeof(void *);

-- 
Alexandre Oliva    Enjoy Guaranį, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

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