Author: Timm Baeder Date: 2023-10-14T09:17:35+02:00 New Revision: a653749acab8d5cb84e7f15cccc97e76ebe8c84b
URL: https://github.com/llvm/llvm-project/commit/a653749acab8d5cb84e7f15cccc97e76ebe8c84b DIFF: https://github.com/llvm/llvm-project/commit/a653749acab8d5cb84e7f15cccc97e76ebe8c84b.diff LOG: [clang][Interp] Implement compound assign operators on bitfields (#67306) Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/bitfields.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 2b745d6a1509868..71aac8c6245c5af 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1170,8 +1170,13 @@ bool ByteCodeExprGen<Emitter>::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 e078704fce51ff0..9a144e2f0d9610e 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, ""); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits