re PR c++/31513 (Miscompilation of Function Passing Bit Field Value to Function)
authorMark Mitchell <mark@codesourcery.com>
Wed, 18 Apr 2007 03:36:18 +0000 (03:36 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 18 Apr 2007 03:36:18 +0000 (03:36 +0000)
PR c++/31513
* call.c (convert_for_arg_passing): Convert bitfields to their
declared types.

PR c++/31513
* g++.dg/expr/bitfield8.C: New test.

From-SVN: r123939

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/bitfield8.C [new file with mode: 0644]

index 1b7172f4424d935daacaf28e7b51677e8de33f87..8aad37a5f9a3599ec3700684d44909a8a33960fe 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-17  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/31513
+       * call.c (convert_for_arg_passing): Convert bitfields to their
+       declared types.
+
 2007-04-17  Simon Martin  <simartin@users.sourceforge.net>
 
        PR c++/31517
index 0b0bb646d22294de0eea81a81b5fbf1e28ba7b3c..abccb4e7e4e3fe4d66cd50a2c718b31eeb971f7d 100644 (file)
@@ -4713,6 +4713,7 @@ type_passed_as (tree type)
 tree
 convert_for_arg_passing (tree type, tree val)
 {
+  val = convert_bitfield_to_declared_type (val);
   if (val == error_mark_node)
     ;
   /* Pass classes with copy ctors by invisible reference.  */
index a1625efe187ff906e6a564bd67509190cd264770..fe20b61b743c9e0e7148dd839a15d7fc3a24717b 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-17  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/31513
+       * g++.dg/expr/bitfield8.C: New test.
+
 2007-04-17  Joseph Myers  <joseph@codesourcery.com>
             Richard Sandiford  <richard@codesourcery.com>
 
diff --git a/gcc/testsuite/g++.dg/expr/bitfield8.C b/gcc/testsuite/g++.dg/expr/bitfield8.C
new file mode 100644 (file)
index 0000000..566109c
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/31513
+// { dg-do run }
+
+extern "C" void abort();
+
+struct tree_type {
+  unsigned int precision : 9;
+};
+
+void bork(unsigned int i) {
+  if (i != 7)
+    abort();
+}
+
+void foo(struct tree_type *t)
+{
+  bork(t->precision);
+}
+
+int main() {
+  tree_type t;
+  t.precision = 7;
+  foo(&t);
+}