Skip to content

Commit

Permalink
[IR] Rename BinaryOperator::init to AssertOK and remove argument. Rep…
Browse files Browse the repository at this point in the history
…lace default case in switch with llvm_unreachable since all valid opcodes are covered.

This method doesn't do any initializing. It just contains asserts. So renaming to AssertOK makes it consistent with similar instructions in other Instruction classes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306277 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Jun 26, 2017
1 parent 330bfed commit 8edc5b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
//===----------------------------------------------------------------------===//

class BinaryOperator : public Instruction {
void AssertOK();

protected:
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
const Twine &Name, Instruction *InsertBefore);
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
const Twine &Name, BasicBlock *InsertAtEnd);

void init(BinaryOps iType);

// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;

Expand Down
11 changes: 5 additions & 6 deletions lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,8 +1995,8 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
InsertBefore) {
Op<0>() = S1;
Op<1>() = S2;
init(iType);
setName(Name);
AssertOK();
}

BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
Expand All @@ -2008,17 +2008,17 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
InsertAtEnd) {
Op<0>() = S1;
Op<1>() = S2;
init(iType);
setName(Name);
AssertOK();
}

void BinaryOperator::init(BinaryOps iType) {
void BinaryOperator::AssertOK() {
Value *LHS = getOperand(0), *RHS = getOperand(1);
(void)LHS; (void)RHS; // Silence warnings.
assert(LHS->getType() == RHS->getType() &&
"Binary operator operand types must match!");
#ifndef NDEBUG
switch (iType) {
switch (getOpcode()) {
case Add: case Sub:
case Mul:
assert(getType() == LHS->getType() &&
Expand Down Expand Up @@ -2075,8 +2075,7 @@ void BinaryOperator::init(BinaryOps iType) {
assert(getType()->isIntOrIntVectorTy() &&
"Tried to create a logical operation on a non-integral type!");
break;
default:
break;
default: llvm_unreachable("Invalid opcode provided");
}
#endif
}
Expand Down

0 comments on commit 8edc5b1

Please sign in to comment.