From 04941f7657cd5e392e3b9e3bf217a5696ecde77a Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 6 Feb 2008 20:31:43 +0000 Subject: [PATCH] re PR c++/35056 (ICE in copy_to_mode_reg, at explow.c:621) gcc/cp/ChangeLog: PR c++/35056 * tree.c: Include tree-flow.h. (build_target_expr): Check type compatibility. * Make-lang.in (cp/tree.o): Depend on $(TREE_FLOW_H). * call.c (convert_like_real): Convert bitfield to expected type. gcc/testsuite/ChangeLog: PR c++/35056 * g++.dg/conversion/bitfield8.C: New. From-SVN: r132158 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/Make-lang.in | 4 ++-- gcc/cp/call.c | 2 ++ gcc/cp/tree.c | 10 +++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/conversion/bitfield8.C | 16 ++++++++++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/conversion/bitfield8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3aa5e761be4..e609de4215d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2008-02-06 Alexandre Oliva + + PR c++/35056 + * tree.c: Include tree-flow.h. + (build_target_expr): Check type compatibility. + * Make-lang.in (cp/tree.o): Depend on $(TREE_FLOW_H). + * call.c (convert_like_real): Convert bitfield to expected type. + 2008-02-06 Douglas Gregor PR c++/35049 diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 500f7121d1e..0aea4cf4013 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -1,6 +1,6 @@ # Top level -*- makefile -*- fragment for GNU C++. # Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2007 +# 2005, 2007, 2008 # Free Software Foundation, Inc. #This file is part of GCC. @@ -261,7 +261,7 @@ cp/cvt.o: cp/cvt.c $(CXX_TREE_H) $(TM_H) cp/decl.h $(FLAGS_H) toplev.h \ cp/search.o: cp/search.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h $(RTL_H) cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h $(RTL_H) \ insn-config.h $(INTEGRATE_H) $(TREE_INLINE_H) $(REAL_H) gt-cp-tree.h \ - $(TARGET_H) debug.h + $(TARGET_H) debug.h $(TREE_FLOW_H) cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H) cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h convert.h \ $(TARGET_H) gt-cp-rtti.h diff --git a/gcc/cp/call.c b/gcc/cp/call.c index c4e4c793982..745c8e8d50a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4507,6 +4507,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, expr, ref_type); return error_mark_node; } + if (lvalue & clk_bitfield) + expr = convert_bitfield_to_declared_type (expr); expr = build_target_expr_with_type (expr, type); } diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7459266d43a..b14462fd339 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1,6 +1,6 @@ /* Language-dependent node constructors for parse phase of GNU compiler. Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. Hacked by Michael Tiemann (tiemann@cygnus.com) @@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "target.h" #include "convert.h" +#include "tree-flow.h" static tree bot_manip (tree *, int *, void *); static tree bot_replace (tree *, int *, void *); @@ -259,6 +260,13 @@ build_target_expr (tree decl, tree value) { tree t; +#ifdef ENABLE_CHECKING + gcc_assert (VOID_TYPE_P (TREE_TYPE (value)) + || TREE_TYPE (decl) == TREE_TYPE (value) + || useless_type_conversion_p (TREE_TYPE (decl), + TREE_TYPE (value))); +#endif + t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value, cxx_maybe_build_cleanup (decl), NULL_TREE); /* We always set TREE_SIDE_EFFECTS so that expand_expr does not diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b54aea98f65..aedc9a3a9da 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-02-06 Alexandre Oliva + + PR c++/35056 + * g++.dg/conversion/bitfield8.C: New. + 2008-02-06 Douglas Gregor * g++.dg/ext/vector13.C: Fix for compilation under -pedantic. diff --git a/gcc/testsuite/g++.dg/conversion/bitfield8.C b/gcc/testsuite/g++.dg/conversion/bitfield8.C new file mode 100644 index 00000000000..dbc62fade5d --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/bitfield8.C @@ -0,0 +1,16 @@ +// PR c++/35056 +// { dg-do compile } +// { dg-options "-O2" } + +enum EBorderStyle { bla = 1 }; +inline bool compare_ref(const unsigned int &t, const EBorderStyle &u) +{ return t == u; } +inline bool compare_val(const unsigned int t, const EBorderStyle u) +{ return t == u; } +struct S { + unsigned m_style : 4; +}; +void call_ref (S *s, EBorderStyle v) +{ if (!compare_ref(s->m_style, v)) s->m_style = v; } +void call_val (S *s, EBorderStyle v) +{ if (!compare_val(s->m_style, v)) s->m_style = v; }