Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -229,6 +229,11 @@ if (!this->emitStore(*T, BO)) return false; return DiscardResult ? this->emitPopPtr(BO) : true; + case BO_And: + return Discard(this->emitAnd(*T, BO)); + case BO_Or: + case BO_LAnd: + case BO_LOr: default: return this->bail(BO); } Index: clang/lib/AST/Interp/Integral.h =================================================================== --- clang/lib/AST/Interp/Integral.h +++ clang/lib/AST/Interp/Integral.h @@ -212,6 +212,11 @@ return false; } + static bool band(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 @@ -158,6 +158,23 @@ return AddSubMulHelper(S, OpPC, Bits, LHS, RHS); } +/// 1) Pops the RHS from the stack. +/// 2) Pops the LHS from the stack. +/// 3) Pushes 'LHS & RHS' on the stack +template ::T> +bool And(InterpState &S, CodePtr OpPC) { + const T &RHS = S.Stk.pop(); + const T &LHS = S.Stk.pop(); + + unsigned Bits = RHS.bitWidth(); + T Result; + if (!T::band(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 @@ -109,6 +109,11 @@ let HasGroup = 1; } +class IntegerOpcode : Opcode { + let Types = [IntegerTypeClass]; + let HasGroup = 1; +} + //===----------------------------------------------------------------------===// // Jump opcodes //===----------------------------------------------------------------------===// @@ -417,10 +422,8 @@ def Sub : AluOpcode; def Add : AluOpcode; def Mul : AluOpcode; -def Rem : Opcode { - let Types = [IntegerTypeClass]; - let HasGroup = 1; -} +def Rem : IntegerOpcode; +def And : IntegerOpcode; def Div : Opcode { let Types = [NumberTypeClass]; let HasGroup = 1;