diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 2b745d6a150986..71aac8c6245c5a 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1170,8 +1170,13 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator( } // And store the result in LHS. - if (DiscardResult) + if (DiscardResult) { + if (LHS->refersToBitField()) + return this->emitStoreBitFieldPop(*ResultT, E); return this->emitStorePop(*ResultT, E); + } + if (LHS->refersToBitField()) + return this->emitStoreBitField(*ResultT, E); return this->emitStore(*ResultT, E); } diff --git a/clang/test/AST/Interp/bitfields.cpp b/clang/test/AST/Interp/bitfields.cpp index e078704fce51ff..9a144e2f0d9610 100644 --- a/clang/test/AST/Interp/bitfields.cpp +++ b/clang/test/AST/Interp/bitfields.cpp @@ -31,8 +31,6 @@ namespace Basic { return a.a = 10; } static_assert(storeA2() == 2, ""); - - // TODO: +=, -=, etc. operators. } namespace Overflow { @@ -45,3 +43,39 @@ namespace Overflow { static_assert(f() == 3, ""); } + +namespace Compound { + struct A { + unsigned int a : 2; + constexpr A() : a(0) {} + constexpr A(int a) : a(a) {} + }; + + constexpr unsigned add() { + A a; + a.a += 10; + return a.a; + } + static_assert(add() == 2, ""); + + constexpr unsigned sub() { + A a; + a.a -= 10; + return a.a; + } + static_assert(sub() == 2, ""); + + constexpr unsigned mul() { + A a(1); + a.a *= 5; + return a.a; + } + static_assert(mul() == 1, ""); + + constexpr unsigned div() { + A a(2); + a.a /= 2; + return a.a; + } + static_assert(div() == 1, ""); +}