Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -527,8 +527,8 @@ const CompoundAssignOperator *E) { const Expr *LHS = E->getLHS(); const Expr *RHS = E->getRHS(); - Optional LT = classify(E->getLHS()->getType()); - Optional RT = classify(E->getRHS()->getType()); + Optional LT = classify(E->getComputationLHSType()); + Optional RT = classify(E->getComputationResultType()); if (!LT || !RT) return false; @@ -554,10 +554,18 @@ if (!this->emitSub(*LT, E)) return false; break; - case BO_MulAssign: + if (!this->emitMul(*LT, E)) + return false; + break; case BO_DivAssign: + if (!this->emitDiv(*LT, E)) + return false; + break; case BO_RemAssign: + if (!this->emitRem(*LT, E)) + return false; + break; case BO_ShlAssign: if (!this->emitShl(*LT, *RT, E)) return false; @@ -567,8 +575,17 @@ return false; break; case BO_AndAssign: + if (!this->emitBitAnd(*LT, E)) + return false; + break; case BO_XorAssign: + if (!this->emitBitXor(*LT, E)) + return false; + break; case BO_OrAssign: + if (!this->emitBitOr(*LT, E)) + return false; + break; default: llvm_unreachable("Unimplemented compound assign operator"); } Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -469,5 +469,129 @@ return (a -= a); } static_assert(subAll(213) == 0, ""); + + constexpr bool BoolOr(bool b1, bool b2) { + bool a; + a = b1; + a |= b2; + return a; + } + static_assert(BoolOr(true, true), ""); + static_assert(BoolOr(true, false), ""); + static_assert(BoolOr(false, true), ""); + static_assert(!BoolOr(false, false), ""); + + constexpr int IntOr(unsigned a, unsigned b) { + unsigned r; + r = a; + r |= b; + return r; + } + static_assert(IntOr(10, 1) == 11, ""); + static_assert(IntOr(1337, -1) == -1, ""); + static_assert(IntOr(0, 12) == 12, ""); + + constexpr bool BoolAnd(bool b1, bool b2) { + bool a; + a = b1; + a &= b2; + return a; + } + static_assert(BoolAnd(true, true), ""); + static_assert(!BoolAnd(true, false), ""); + static_assert(!BoolAnd(false, true), ""); + static_assert(!BoolAnd(false, false), ""); + + constexpr int IntAnd(unsigned a, unsigned b) { + unsigned r; + r = a; + r &= b; + return r; + } + static_assert(IntAnd(10, 1) == 0, ""); + static_assert(IntAnd(1337, -1) == 1337, ""); + static_assert(IntAnd(0, 12) == 0, ""); + + constexpr bool BoolXor(bool b1, bool b2) { + bool a; + a = b1; + a ^= b2; + return a; + } + static_assert(!BoolXor(true, true), ""); + static_assert(BoolXor(true, false), ""); + static_assert(BoolXor(false, true), ""); + static_assert(!BoolXor(false, false), ""); + + constexpr int IntXor(unsigned a, unsigned b) { + unsigned r; + r = a; + r ^= b; + return r; + } + static_assert(IntXor(10, 1) == 11, ""); + static_assert(IntXor(10, 10) == 0, ""); + static_assert(IntXor(12, true) == 13, ""); + + constexpr bool BoolRem(bool b1, bool b2) { + bool a; + a = b1; + a %= b2; + return a; + } + static_assert(!BoolRem(true, true), ""); + static_assert(!BoolRem(false, true), ""); + + constexpr int IntRem(unsigned a, unsigned b) { + unsigned r; + r = a; + r %= b; + return r; + } + static_assert(IntRem(2, 2) == 0, ""); + static_assert(IntRem(2, 1) == 0, ""); + static_assert(IntRem(9, 7) == 2, ""); + + constexpr bool BoolDiv(bool b1, bool b2) { + bool a; + a = b1; + a /= b2; + return a; + } + static_assert(BoolDiv(true, true), ""); + static_assert(!BoolDiv(false, true), ""); + + constexpr int IntDiv(unsigned a, unsigned b) { + unsigned r; + r = a; + r /= b; + return r; + } + static_assert(IntDiv(2, 2) == 1, ""); + static_assert(IntDiv(12, 20) == 0, ""); + static_assert(IntDiv(2, 1) == 2, ""); + static_assert(IntDiv(9, 7) == 1, ""); + + constexpr bool BoolMul(bool b1, bool b2) { + bool a; + a = b1; + a *= b2; + return a; + } + static_assert(BoolMul(true, true), ""); + static_assert(!BoolMul(true, false), ""); + static_assert(!BoolMul(false, true), ""); + static_assert(!BoolMul(false, false), ""); + + constexpr int IntMul(unsigned a, unsigned b) { + unsigned r; + r = a; + r *= b; + return r; + } + static_assert(IntMul(2, 2) == 4, ""); + static_assert(IntMul(12, 20) == 240, ""); + static_assert(IntMul(2, 1) == 2, ""); + static_assert(IntMul(9, 7) == 63, ""); }; #endif