Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -273,6 +273,7 @@ case BO_And: return Discard(this->emitBitAnd(*T, BO)); case BO_Or: + return Discard(this->emitBitOr(*T, BO)); case BO_LAnd: case BO_LOr: default: Index: clang/lib/AST/Interp/Integral.h =================================================================== --- clang/lib/AST/Interp/Integral.h +++ clang/lib/AST/Interp/Integral.h @@ -217,6 +217,11 @@ return false; } + static bool bitOr(Integral A, Integral B, unsigned OpBits, Integral *R) { + *R = Integral(A.V | B.V); + return false; + } + static bool neg(Integral A, Integral *R) { *R = -A; return false; Index: clang/lib/AST/Interp/Interp.h =================================================================== --- clang/lib/AST/Interp/Interp.h +++ clang/lib/AST/Interp/Interp.h @@ -175,6 +175,23 @@ return false; } +/// 1) Pops the RHS from the stack. +/// 2) Pops the LHS from the stack. +/// 3) Pushes 'LHS | RHS' on the stack +template ::T> +bool BitOr(InterpState &S, CodePtr OpPC) { + const T &RHS = S.Stk.pop(); + const T &LHS = S.Stk.pop(); + + unsigned Bits = RHS.bitWidth(); + T Result; + if (!T::bitOr(LHS, RHS, Bits, &Result)) { + S.Stk.push(Result); + return true; + } + return false; +} + /// 1) Pops the RHS from the stack. /// 2) Pops the LHS from the stack. /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS). Index: clang/lib/AST/Interp/Opcodes.td =================================================================== --- clang/lib/AST/Interp/Opcodes.td +++ clang/lib/AST/Interp/Opcodes.td @@ -432,6 +432,7 @@ let HasGroup = 1; } def BitAnd : IntegerOpcode; +def BitOr : IntegerOpcode; def Div : Opcode { let Types = [NumberTypeClass]; let HasGroup = 1; Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -271,6 +271,15 @@ static_assert((0 & gimme(12)) == 0, ""); }; +namespace bitOr { + static_assert((10 | 1) == 11, ""); + static_assert((10 | 10) == 10, ""); + + static_assert((1337 | -1) == -1, ""); + static_assert((0 | gimme(12)) == 12, ""); + static_assert((12 | true) == 13, ""); +}; + namespace floats { constexpr int i = 2; constexpr float f = 1.0f;