From: Richard Guenther Date: Tue, 5 Feb 2008 12:26:53 +0000 (+0000) Subject: backport: re PR c++/33819 (Miscompiled shift of C++ bitfield) X-Git-Tag: prereleases/gcc-4.2.4-rc1~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be56cf339f1f44d5d2e84986731be098853cd896;p=thirdparty%2Fgcc.git backport: re PR c++/33819 (Miscompiled shift of C++ bitfield) 2008-02-05 Richard Guenther Backport from mainline: 2008-01-16 Richard Guenther PR c++/33819 * typeck.c (is_bitfield_expr_with_lowered_type): Recurse for conversions to type variants. * g++.dg/torture/pr33819.C: New testcase. From-SVN: r132118 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 37c7a2f8693a..408126bea378 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2008-02-05 Richard Guenther + + Backport from mainline: + 2008-01-16 Richard Guenther + + PR c++/33819 + * typeck.c (is_bitfield_expr_with_lowered_type): Recurse + for conversions to type variants. + 2008-02-01 Release Manager * GCC 4.2.3 released. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9e8ca6eabe14..76ac3f03ee6e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1443,6 +1443,13 @@ is_bitfield_expr_with_lowered_type (tree exp) return DECL_BIT_FIELD_TYPE (field); } + case NOP_EXPR: + case CONVERT_EXPR: + if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (exp, 0))) + == TYPE_MAIN_VARIANT (TREE_TYPE (exp))) + return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0)); + /* Fallthrough. */ + default: return NULL_TREE; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3c1670106c7..feda984adaf9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2008-02-05 Richard Guenther + + Backport from mainline: + 2008-01-16 Richard Guenther + + PR c/34768 + * gcc.c-torture/execute/pr34768-1.c: New testcase. + * gcc.c-torture/execute/pr34768-2.c: Likewise. + 2008-02-04 Daniel Franke * gfortran.dg/where_operator_assign_4.f90: Fix typo in error message diff --git a/gcc/testsuite/g++.dg/torture/pr33819.C b/gcc/testsuite/g++.dg/torture/pr33819.C new file mode 100644 index 000000000000..a2f868daee3c --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr33819.C @@ -0,0 +1,22 @@ +/* { dg-do run } */ + +class s +{ +public: + s(long long aa) : a(aa), i1(0) { } + long long id() const { return (this->a << 16) >> 16; } + bool operator< (s sv) { return this->a < sv.id(); } +private: + long long a : 48; + int i1 : 16; +}; +s g(1); +extern "C" void abort (void); +int +main(int, char**) +{ + if (g < (1LL << 38) - 1) + return 0; + abort (); +} +