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]

Re: prevent creation of invalid static constructors from gimplifier


Hello Ian,

Ian Lance Taylor wrote:
> I also think that when you push it all the way, you'll find that
> nc_elts drops out of categorize_ctor_elements_1.  But if it doesn't,
> that's OK.

 Here's another take, hopefully closer to what you envisioned :)

 The idea is to propagate your return value suggestion to the categorize_1
 helper, indeed getting rid of the nc_elts argument, and potentially saving
 a number of useless calls to initializer_constant_valid_p.

 In addition, I tried to minimize the initializer_constant_valid_p
 synchronization issue by exposing the current internal test in the latter
 as a common macro predicate used in both functions. This is

	(CONSTRUCTOR_STATIC_FROM_ELTS_P): New macro.  Whether a constructor
	node is a valid static constant initializer if all its elements are.

 in the ChangeLog below.

 This patch + a couple of instrumentation bits in categorize_1
 bootstrapped and successfully passed regression tests on i686-pc-linux-gnu
 with languages=all,ada from a 0713 source base. I checked that the same
 source tree with the instrumentation removed bootstraps as well.
 
 The instrumentation checked
 "const_p == (initializer_constant_valid_p (...) != NULL_TREE)"
 and counted how many times this passed per compilation unit. FWIW, 28711
 times during a bootstrap stage and 72021 time during make -k check.

 I'll of course be happy to address further comments you may have.

 Thanks for your feedback,

 Olivier

 2006-07-17  Olivier Hainque  <hainque@adacore.com>

	* tree.h (categorize_ctor_elements): Adjust prototype and add
	descriptive comment, both in accordance with the interface change
	described below.
	(CONSTRUCTOR_STATIC_FROM_ELTS_P): New macro.  Whether a constructor
	node is a valid static constant initializer if all its elements are.
	* varasm.c (initializer_constant_valid_p) <CONSTRUCTOR value>: Use it.
	* expr.c (categorize_ctor_elements_1): Return whether the constructor
	is a valid constant initializer instead of computing the number of
	non-constant elements.  Use CONSTRUCTOR_STATIC_FROM_ELTS_P for this
	purpose.  Replace the head comment with an indication that this is a
	helper for categorize_ctor_elements.
	(categorize_ctor_elements): Same interface change as for the _1
	helper.  Former head comment from this helper moved here, adjusted to
	account for the interface changes.
	(mostly_zeros_p): Adjust call to categorize_ctor_elements.
	(all_zeros_p): Likewise.	
	* gimplify.c (gimplify_init_constructor): Decide whether we can make
	static versions of the constructor from the categorize_ctor_elements
	return value instead of the formerly computed number of non-constant
	elements.

	* gnat.dg/outer_agg_bitfield_constructor.adb: New test.
	* gnat.dg/nested_agg_bitfield_constructor.adb: New test.
	

Attachment: bitfield-ctor.dif
Description: Text document


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