C++ PATCH: PR 11852

Mark Mitchell mark@codesourcery.com
Sun Sep 7 23:51:00 GMT 2003


This PR demonstrated the presence of totally bogus code in
initializer_constant_valid_p; for a CONSTRUCTOR, only the last element
of the CONSTRUCTOR was being checked.

Bootstrapped and tested on i686-pc-linux-gnu, applied on the mainline
and on the branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-09-07  Mark Mitchell  <mark@codesourcery.com>

	PR c++/11852
	* varasm.c (initializer_constant_valid_p): Correct logic for
	CONSTRUCTORs.

2003-09-07  Mark Mitchell  <mark@codesourcery.com>

	PR c++/11852
	* g++.dg/init/struct1.C: New test.

Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.381
diff -c -5 -p -r1.381 varasm.c
*** varasm.c	5 Sep 2003 04:24:26 -0000	1.381
--- varasm.c	7 Sep 2003 23:46:33 -0000
*************** initializer_constant_valid_p (tree value
*** 3474,3488 ****
      case CONSTRUCTOR:
        if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
  	   || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
  	  && TREE_CONSTANT (value)
  	  && CONSTRUCTOR_ELTS (value))
! 	return
! 	  initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
! 					endtype);
  
!       return TREE_STATIC (value) ? null_pointer_node : 0;
  
      case INTEGER_CST:
      case VECTOR_CST:
      case REAL_CST:
      case STRING_CST:
--- 3474,3504 ----
      case CONSTRUCTOR:
        if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
  	   || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
  	  && TREE_CONSTANT (value)
  	  && CONSTRUCTOR_ELTS (value))
! 	{
! 	  tree elt;
! 	  bool absolute = true;
  
! 	  for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
! 	    {
! 	      tree reloc;
! 	      value = TREE_VALUE (elt);
! 	      reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
! 	      if (!reloc)
! 		return NULL_TREE;
! 	      if (reloc != null_pointer_node)
! 		absolute = false;
! 	    }
! 	  /* For a non-absolute relocation, there is no single
! 	     variable that can be "the variable that determines the
! 	     relocation."  */
! 	  return absolute ? null_pointer_node : error_mark_node;
! 	}
! 
!       return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
  
      case INTEGER_CST:
      case VECTOR_CST:
      case REAL_CST:
      case STRING_CST:
Index: testsuite/g++.dg/init/struct1.C
===================================================================
RCS file: testsuite/g++.dg/init/struct1.C
diff -N testsuite/g++.dg/init/struct1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/struct1.C	7 Sep 2003 23:46:05 -0000
***************
*** 0 ****
--- 1,6 ----
+ struct bug {
+   const char *name;
+   unsigned long type;
+ };
+ 
+ struct bug s = { 0, (unsigned long) &s | 1 };



More information about the Gcc-patches mailing list