Skip to content

Commit d082f1f

Browse files
committed
[clang][bytecode] Only booleans can be inverted
No need to have the Inv() function be templated.
1 parent 6ed2a6b commit d082f1f

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

clang/lib/AST/ByteCode/Boolean.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Boolean final {
4444
Boolean operator-() const { return Boolean(V); }
4545
Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); }
4646
Boolean operator~() const { return Boolean(true); }
47+
Boolean operator!() const { return Boolean(!V); }
4748

4849
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
4950
explicit operator Ty() const {

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,7 +5112,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
51125112
if (!this->visitBool(SubExpr))
51135113
return false;
51145114

5115-
if (!this->emitInvBool(E))
5115+
if (!this->emitInv(E))
51165116
return false;
51175117

51185118
if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
@@ -5231,7 +5231,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
52315231
return false;
52325232
if (!this->emitComplexBoolCast(SubExpr))
52335233
return false;
5234-
if (!this->emitInvBool(E))
5234+
if (!this->emitInv(E))
52355235
return false;
52365236
if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
52375237
return this->emitCast(PT_Bool, ET, E);

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,15 +656,9 @@ inline bool Divf(InterpState &S, CodePtr OpPC, llvm::RoundingMode RM) {
656656
// Inv
657657
//===----------------------------------------------------------------------===//
658658

659-
template <PrimType Name, class T = typename PrimConv<Name>::T>
660-
bool Inv(InterpState &S, CodePtr OpPC) {
661-
using BoolT = PrimConv<PT_Bool>::T;
662-
const T &Val = S.Stk.pop<T>();
663-
const unsigned Bits = Val.bitWidth();
664-
Boolean R;
665-
Boolean::inv(BoolT::from(Val, Bits), &R);
666-
667-
S.Stk.push<BoolT>(R);
659+
inline bool Inv(InterpState &S, CodePtr OpPC) {
660+
const auto &Val = S.Stk.pop<Boolean>();
661+
S.Stk.push<Boolean>(!Val);
668662
return true;
669663
}
670664

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ def PtrTypeClass : TypeClass {
103103
let Types = [Ptr, FnPtr, MemberPtr];
104104
}
105105

106-
def BoolTypeClass : TypeClass {
107-
let Types = [Bool];
108-
}
109-
110106
def NonPtrTypeClass : TypeClass {
111107
let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float]);
112108
}
@@ -574,11 +570,8 @@ def Shr : Opcode {
574570
// Unary operators.
575571
//===----------------------------------------------------------------------===//
576572

577-
// [Real] -> [Real]
578-
def Inv: Opcode {
579-
let Types = [BoolTypeClass];
580-
let HasGroup = 1;
581-
}
573+
// [Bool] -> [Bool]
574+
def Inv: Opcode;
582575

583576
// Increment and decrement.
584577
def Inc: AluOpcode;

0 commit comments

Comments
 (0)