From 431ed7a1312eaaaac39d3044ad01fd8314f25c24 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Wed, 18 Apr 2007 03:36:18 +0000 Subject: [PATCH] re PR c++/31513 (Miscompilation of Function Passing Bit Field Value to Function) 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 | 6 ++++++ gcc/cp/call.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/expr/bitfield8.C | 24 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/g++.dg/expr/bitfield8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b7172f4424..8aad37a5f9a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-04-17 Mark Mitchell + + PR c++/31513 + * call.c (convert_for_arg_passing): Convert bitfields to their + declared types. + 2007-04-17 Simon Martin PR c++/31517 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 0b0bb646d22..abccb4e7e4e 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a1625efe187..fe20b61b743 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-04-17 Mark Mitchell + + PR c++/31513 + * g++.dg/expr/bitfield8.C: New test. + 2007-04-17 Joseph Myers Richard Sandiford diff --git a/gcc/testsuite/g++.dg/expr/bitfield8.C b/gcc/testsuite/g++.dg/expr/bitfield8.C new file mode 100644 index 00000000000..566109cdd3d --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bitfield8.C @@ -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); +} -- 2.30.2