Skip to content

Commit aa4e34b

Browse files
authored
[clang][Interp] Implement bitwise operations for IntegralAP (#71807)
1 parent af05f9f commit aa4e34b

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
@@ -218,21 +218,19 @@ template <bool Signed> class IntegralAP final {
218218

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

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

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

clang/test/AST/Interp/intap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,16 @@ namespace Bitfields {
172172
// expected-warning {{changes value from 100 to 0}}
173173
}
174174

175+
namespace BitOps {
176+
constexpr unsigned __int128 UZero = 0;
177+
constexpr unsigned __int128 Max = ~UZero;
178+
static_assert(Max == ~0, "");
179+
static_assert((Max & 0) == 0, "");
180+
static_assert((UZero | 0) == 0, "");
181+
static_assert((Max ^ Max) == 0, "");
182+
static_assert((Max & 1) == 1, "");
183+
static_assert((UZero | 1) == 1, "");
184+
static_assert((Max ^ UZero) == Max, "");
185+
}
186+
175187
#endif

0 commit comments

Comments
 (0)