re PR c++/27505 (ICE in const folding with bitfields)

PR c++/27505
	* call.c (convert_like_real): Convert bitfields to their declared
	types when forming an rvalue.
	* tree.c (convert_bitfield_to_declared_type): New function.
	(rvalue): Use it.
	* cp-tree.h (convert_bitfield_to_declare_type): Declare it.
	PR c++/27505
	* g++.dg/expr/bitfield1.C: New test.

From-SVN: r113803
This commit is contained in:
Mark Mitchell 2006-05-15 22:54:19 +00:00 committed by Mark Mitchell
parent 34a660ec3d
commit e103969791
6 changed files with 46 additions and 5 deletions

View File

@ -1,3 +1,12 @@
2006-05-15 Mark Mitchell <mark@codesourcery.com>
PR c++/27505
* call.c (convert_like_real): Convert bitfields to their declared
types when forming an rvalue.
* tree.c (convert_bitfield_to_declared_type): New function.
(rvalue): Use it.
* cp-tree.h (convert_bitfield_to_declare_type): Declare it.
2006-05-15 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27582

View File

@ -4328,6 +4328,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
switch (convs->kind)
{
case ck_rvalue:
expr = convert_bitfield_to_declared_type (expr);
if (! IS_AGGR_TYPE (totype))
return expr;
/* Else fall through. */

View File

@ -4335,6 +4335,7 @@ extern tree cp_add_pending_fn_decls (void*,tree);
extern int cp_auto_var_in_fn_p (tree,tree);
extern tree fold_if_not_in_template (tree);
extern tree rvalue (tree);
extern tree convert_bitfield_to_declared_type (tree);
/* in typeck.c */
extern int string_conv_p (tree, tree, int);

View File

@ -362,22 +362,35 @@ get_target_expr (tree init)
return build_target_expr_with_type (init, TREE_TYPE (init));
}
/* If EXPR is a bitfield reference, convert it to the declared type of
the bitfield, and return the resulting expression. Otherwise,
return EXPR itself. */
tree
convert_bitfield_to_declared_type (tree expr)
{
tree bitfield_type;
bitfield_type = is_bitfield_expr_with_lowered_type (expr);
if (bitfield_type)
expr = cp_convert (TYPE_MAIN_VARIANT (bitfield_type), expr);
return expr;
}
/* EXPR is being used in an rvalue context. Return a version of EXPR
that is marked as an rvalue. */
tree
rvalue (tree expr)
{
tree type;
expr = convert_bitfield_to_declared_type (expr);
if (real_lvalue_p (expr))
{
type = is_bitfield_expr_with_lowered_type (expr);
if (type)
return cp_convert (TYPE_MAIN_VARIANT (type), expr);
type = TREE_TYPE (expr);
tree type;
/* [basic.lval]
Non-class rvalues always have cv-unqualified types. */
type = TREE_TYPE (expr);
if (!CLASS_TYPE_P (type))
type = TYPE_MAIN_VARIANT (type);
expr = build1 (NON_LVALUE_EXPR, type, expr);

View File

@ -1,3 +1,8 @@
2006-05-15 Mark Mitchell <mark@codesourcery.com>
PR c++/27505
* g++.dg/expr/bitfield1.C: New test.
2006-05-15 Richard Guenther <rguenther@suse.de>
PR tree-optimization/27603

View File

@ -0,0 +1,12 @@
// PR c++/27505
struct s {
bool field:8;
};
void
foo (struct s *p)
{
if (!p->field)
;
}