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: [PR c++/35909] fix const ref binding to demoted bitfield


On Apr 28, 2008, Jakub Jelinek <jakub@redhat.com> wrote:

> On Thu, Apr 24, 2008 at 10:13:55AM +0200, Richard Guenther wrote:
>> 2008/4/24 Alexandre Oliva <aoliva@redhat.com>:
>> >  Tested on trunk x86_64-linux-gnu.  Ok to install?
>> >
>> >  Ok for 4.3 branch if it passes there as well?

>> fold_convert instead of fold (build_nop ())?

> Then the if (type != TREE_TYPE (expr)) guard wouldn't be needed either.
> Just expr = fold_convert (type, expr); unconditionally.

It's not clear whether the suggestions above were meant as approval for
the patch, so I'm refraining from checking it in with the change.
Here's what I'm finishing testing in the 4.3 branch:

for  gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/35909
	* call.c (convert_like_real): Convert bitfield to desired type
	before creating temporary.

for  gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/35909
	* g++.dg/conversion/bitfield9.C: New.

Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c.orig	2008-04-22 03:26:25.000000000 -0300
+++ gcc/cp/call.c	2008-04-28 17:06:07.000000000 -0300
@@ -4580,7 +4580,10 @@ convert_like_real (conversion *convs, tr
 		return error_mark_node;
 	      }
 	    if (lvalue & clk_bitfield)
-	      expr = convert_bitfield_to_declared_type (expr);
+	      {
+		expr = convert_bitfield_to_declared_type (expr);
+		expr = fold_convert (type, expr);
+	      }
 	    expr = build_target_expr_with_type (expr, type);
 	  }
 
Index: gcc/testsuite/g++.dg/conversion/bitfield9.C
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/conversion/bitfield9.C	2008-04-22 03:26:27.000000000 -0300
@@ -0,0 +1,17 @@
+// PR c++/35909
+// { dg-do compile }
+
+struct MidiCommand
+{
+  unsigned data1 : 8;
+};
+
+void g(const unsigned char &);
+void h(const unsigned int &);
+
+void f(MidiCommand mc)
+{
+  g(mc.data1);
+  h(mc.data1);
+}
+

-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member       ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}

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