mirror of https://github.com/llvm/torch-mlir
build: fix code so that the compiler does not emit warnings (#871)
When compiling without assertions (i.e. in `NDEBUG` mode), a handful of statements turn to NOPs, which results in warnings such as missing return statement or unused variables and function. This patch replaces such statements with `llvm_unreachable()`, which informs the compiler about program termination regardless of the `NDEBUG` mode. This also enables torch-mlir to be compiled using the flags `-Wall`, `-Wextra`, `-Wpedantic`, and `-Werror`.pull/905/head snapshot-20220525.473
parent
cec5aeedb0
commit
029cd54327
|
@ -403,6 +403,7 @@ bool ScatterOp::payloadUsesValueFromOperand(OpOperand *opOperand) {
|
||||||
bbArgNumber = 0; // block arg 0 is `update`.
|
bbArgNumber = 0; // block arg 0 is `update`.
|
||||||
else {
|
else {
|
||||||
bool isValidOperand = operand == indices() || operand == original();
|
bool isValidOperand = operand == indices() || operand == original();
|
||||||
|
(void)isValidOperand;
|
||||||
assert(isValidOperand &&
|
assert(isValidOperand &&
|
||||||
"operand must belong to the current tm_tensor.scatter op");
|
"operand must belong to the current tm_tensor.scatter op");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -47,7 +47,7 @@ static Value createComparisonTemplate(OpBuilder &b, Location loc, Type type,
|
||||||
if (intType.isSigned())
|
if (intType.isSigned())
|
||||||
return b.create<arith::CmpIOp>(loc, ispred, lhs, rhs);
|
return b.create<arith::CmpIOp>(loc, ispred, lhs, rhs);
|
||||||
}
|
}
|
||||||
assert(false && "Unhandled element type for comparison");
|
llvm_unreachable("Unhandled element type for comparison");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Value createGreaterThan(OpBuilder &b, Location loc, Type elementalType,
|
static Value createGreaterThan(OpBuilder &b, Location loc, Type elementalType,
|
||||||
|
|
|
@ -115,6 +115,7 @@ static torch_upstream::TypeKind getTypeKind(Type type) {
|
||||||
/// types.
|
/// types.
|
||||||
static Optional<Type> meetElementTypes(Type lhs, Type rhs) {
|
static Optional<Type> meetElementTypes(Type lhs, Type rhs) {
|
||||||
auto isNullOrBuiltIn = [](Type type) { return !type || isBuiltInType(type); };
|
auto isNullOrBuiltIn = [](Type type) { return !type || isBuiltInType(type); };
|
||||||
|
(void)isNullOrBuiltIn;
|
||||||
assert(isNullOrBuiltIn(lhs) && "`lhs` must be a builtin type");
|
assert(isNullOrBuiltIn(lhs) && "`lhs` must be a builtin type");
|
||||||
assert(isNullOrBuiltIn(rhs) && "`rhs` must be a builtin type");
|
assert(isNullOrBuiltIn(rhs) && "`rhs` must be a builtin type");
|
||||||
|
|
||||||
|
@ -173,6 +174,7 @@ struct ValueKnowledge {
|
||||||
|
|
||||||
void setScalarType(Type type) {
|
void setScalarType(Type type) {
|
||||||
bool isValidScalarType = type.isa<NumberType, IntType, Torch::FloatType>();
|
bool isValidScalarType = type.isa<NumberType, IntType, Torch::FloatType>();
|
||||||
|
(void)isValidScalarType;
|
||||||
assert(isValidScalarType &&
|
assert(isValidScalarType &&
|
||||||
"scalarType can only be one of NumberType, IntType and FloatType");
|
"scalarType can only be one of NumberType, IntType and FloatType");
|
||||||
scalarType = type;
|
scalarType = type;
|
||||||
|
|
Loading…
Reference in New Issue