diff options
author | Mark Mitchell <mmitchel@gcc.gnu.org> | 2007-07-27 17:13:29 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2007-07-27 17:13:29 +0000 |
commit | 83144bd60ce827e50425094f47f39aed75324cd6 (patch) | |
tree | 8699cc4407ba2a4a6d5b61ba61f8dcc7daeccc44 /gcc/cp | |
parent | b8475dd604f7461fef93b0fe2b9c52b4a6d206f0 (diff) | |
download | gcc-83144bd60ce827e50425094f47f39aed75324cd6.zip gcc-83144bd60ce827e50425094f47f39aed75324cd6.tar.gz gcc-83144bd60ce827e50425094f47f39aed75324cd6.tar.bz2 |
re PR c++/32346 (long long bitfield passed to int argument incorrectly)
PR c++/32346
* call.c (convert_for_arg_passing): Only widen bitfields to their
declared types if necessary.
PR c++/32346
* g++.dg/expr/bitfield9.C: New test.
From-SVN: r126986
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 22 |
2 files changed, 27 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7b1dc92..3c7b8c6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-07-27 Mark Mitchell <mark@codesourcery.com> + + PR c++/32346 + * call.c (convert_for_arg_passing): Only widen bitfields to their + declared types if necessary. + 2007-07-25 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * parser.c (cp_parser_string_literal, cp_parser_sizeof_operand): diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 82f8666..1f220f0 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4752,7 +4752,27 @@ type_passed_as (tree type) tree convert_for_arg_passing (tree type, tree val) { - val = convert_bitfield_to_declared_type (val); + tree bitfield_type; + + /* If VAL is a bitfield, then -- since it has already been converted + to TYPE -- it cannot have a precision greater than TYPE. + + If it has a smaller precision, we must widen it here. For + example, passing "int f:3;" to a function expecting an "int" will + not result in any conversion before this point. + + If the precision is the same we must not risk widening. For + example, the COMPONENT_REF for a 32-bit "long long" bitfield will + often have type "int", even though the C++ type for the field is + "long long". If the value is being passed to a function + expecting an "int", then no conversions will be required. But, + if we call convert_bitfield_to_declared_type, the bitfield will + be converted to "long long". */ + bitfield_type = is_bitfield_expr_with_lowered_type (val); + if (bitfield_type + && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)) + val = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type), val); + if (val == error_mark_node) ; /* Pass classes with copy ctors by invisible reference. */ |