Skip to content

Commit 72b46d8

Browse files
committed
[clang][Interp] Implement bitwise operations for IntegralAP
1 parent c3329b1 commit 72b46d8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

clang/lib/AST/Interp/IntegralAP.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,19 @@ template <bool Signed> class IntegralAP final {
219219

220220
static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits,
221221
IntegralAP *R) {
222-
// FIXME: Implement.
223-
assert(false);
222+
*R = IntegralAP(A.V & B.V);
224223
return false;
225224
}
226225

227226
static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits,
228227
IntegralAP *R) {
229-
assert(false);
228+
*R = IntegralAP(A.V | B.V);
230229
return false;
231230
}
232231

233232
static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits,
234233
IntegralAP *R) {
235-
// FIXME: Implement.
236-
assert(false);
234+
*R = IntegralAP(A.V ^ B.V);
237235
return false;
238236
}
239237

clang/test/AST/Interp/intap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,16 @@ namespace Bitfields {
157157
// expected-warning {{changes value from 100 to 0}}
158158
}
159159

160+
namespace BitOps {
161+
constexpr unsigned __int128 UZero = 0;
162+
constexpr unsigned __int128 Max = ~UZero;
163+
static_assert(Max == ~0, "");
164+
static_assert((Max & 0) == 0, "");
165+
static_assert((UZero | 0) == 0, "");
166+
static_assert((Max ^ Max) == 0, "");
167+
static_assert((Max & 1) == 1, "");
168+
static_assert((UZero | 1) == 1, "");
169+
static_assert((Max ^ UZero) == Max, "");
170+
}
171+
160172
#endif

0 commit comments

Comments
 (0)