Skip to content

Commit

Permalink
[clang][Interp] Implement bitwise operations for IntegralAP (#71807)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Nov 16, 2023
1 parent af05f9f commit aa4e34b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions clang/lib/AST/Interp/IntegralAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,19 @@ template <bool Signed> class IntegralAP final {

static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits,
IntegralAP *R) {
// FIXME: Implement.
assert(false);
*R = IntegralAP(A.V & B.V);
return false;
}

static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits,
IntegralAP *R) {
assert(false);
*R = IntegralAP(A.V | B.V);
return false;
}

static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits,
IntegralAP *R) {
// FIXME: Implement.
assert(false);
*R = IntegralAP(A.V ^ B.V);
return false;
}

Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/Interp/intap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,16 @@ namespace Bitfields {
// expected-warning {{changes value from 100 to 0}}
}

namespace BitOps {
constexpr unsigned __int128 UZero = 0;
constexpr unsigned __int128 Max = ~UZero;
static_assert(Max == ~0, "");
static_assert((Max & 0) == 0, "");
static_assert((UZero | 0) == 0, "");
static_assert((Max ^ Max) == 0, "");
static_assert((Max & 1) == 1, "");
static_assert((UZero | 1) == 1, "");
static_assert((Max ^ UZero) == Max, "");
}

#endif

0 comments on commit aa4e34b

Please sign in to comment.