Skip to content

Commit d37a4df

Browse files
authored
Enable cppcheck rule for 'not', 'or' keywords (#1361)
Using not and or improves readability. The cppcheck rule will help ensure we are doing it consistently.
1 parent 794a433 commit d37a4df

File tree

95 files changed

+210
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+210
-202
lines changed

cppcheck.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<summary>Use make_shared or make_unique instead of new</summary>
108108
</message>
109109
</rule>
110-
<!-- <rule>
110+
<rule>
111111
<tokenlist>raw</tokenlist>
112112
<pattern><![CDATA[ \|\| ]]></pattern>
113113
<message>
@@ -124,7 +124,7 @@
124124
<severity>style</severity>
125125
<summary>Use 'not' instead of !</summary>
126126
</message>
127-
</rule> -->
127+
</rule>
128128
<!-- <rule>
129129
<tokenlist>raw</tokenlist>
130130
<pattern><![CDATA[] (__device__ |__host__ )+(\(|{)]]></pattern>

examples/migraphx/cpp_parse_load_save/parse_load_save.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ int main(int argc, char** argv)
5353

5454
migraphx::program p;
5555

56-
if(cmdOptionExists(argv + 2, argv + argc, "--parse") ||
57-
!cmdOptionExists(argv + 2, argv + argc, "--load"))
56+
if(cmdOptionExists(argv + 2, argv + argc, "--parse") or
57+
not cmdOptionExists(argv + 2, argv + argc, "--load"))
5858
{
5959
std::cout << "Parsing ONNX File" << std::endl;
6060
migraphx::onnx_options options;

examples/migraphx/custom_op_rocblas_kernel/custom_op_rocblas_kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct sscal_custom_op final : migraphx::experimental_custom_op_base
7272
{
7373
throw std::runtime_error("sscal_custom_op must have 2 input arguments");
7474
}
75-
if(inputs[0].lengths().size() != 1 || inputs[0].lengths()[0] != 1)
75+
if(inputs[0].lengths().size() != 1 or inputs[0].lengths()[0] != 1)
7676
{
7777
throw std::runtime_error("first input argument to sscal_custom_op must be a scalar");
7878
}

examples/vision/cpp_mnist/mnist_inference.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ int main(int argc, char** argv)
5151

5252
char** begin = argv + 1;
5353
char** end = argv + argc;
54-
const bool CPU = (std::find(begin, end, std::string("-c")) != end) ||
54+
const bool CPU = (std::find(begin, end, std::string("-c")) != end) or
5555
std::find(begin, end, std::string("--cpu")) != end;
56-
const bool GPU = std::find(begin, end, std::string("-g")) != end ||
56+
const bool GPU = std::find(begin, end, std::string("-g")) != end or
5757
std::find(begin, end, std::string("--gpu")) != end;
58-
const bool FP16 = std::find(begin, end, std::string("-f")) != end ||
58+
const bool FP16 = std::find(begin, end, std::string("-f")) != end or
5959
std::find(begin, end, std::string("--fp16")) != end;
60-
const bool INT8 = std::find(begin, end, std::string("-i")) != end ||
60+
const bool INT8 = std::find(begin, end, std::string("-i")) != end or
6161
std::find(begin, end, std::string("--int8")) != end;
6262
const bool CALIB = std::find(begin, end, std::string("--cal")) != end;
63-
const bool PRINT = std::find(begin, end, std::string("-p")) != end ||
63+
const bool PRINT = std::find(begin, end, std::string("-p")) != end or
6464
std::find(begin, end, std::string("--print")) != end;
6565

6666
migraphx::program prog;
@@ -182,7 +182,7 @@ void read_nth_digit(const int n, std::vector<float>& digit)
182182
const int HEIGHT = 28;
183183
const int WIDTH = 28;
184184

185-
if(!file.is_open())
185+
if(not file.is_open())
186186
{
187187
return;
188188
}

src/api/include/migraphx/migraphx.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ struct shape : MIGRAPHX_CONST_HANDLE_BASE(shape)
588588
return pout;
589589
}
590590

591-
friend bool operator!=(const shape& px, const shape& py) { return !(px == py); }
591+
friend bool operator!=(const shape& px, const shape& py) { return not(px == py); }
592592
};
593593

594594
/**
@@ -647,7 +647,7 @@ struct argument : MIGRAPHX_CONST_HANDLE_BASE(argument)
647647
return pout;
648648
}
649649

650-
friend bool operator!=(const argument& px, const argument& py) { return !(px == py); }
650+
friend bool operator!=(const argument& px, const argument& py) { return not(px == py); }
651651
};
652652

653653
/// A target for compilation
@@ -684,7 +684,7 @@ struct program_parameter_shapes : MIGRAPHX_HANDLE_BASE(program_parameter_shapes)
684684
std::vector<const char*> names() const
685685
{
686686
std::vector<const char*> result(this->size());
687-
if(!result.empty())
687+
if(not result.empty())
688688
{
689689
call(&migraphx_program_parameter_shapes_names, result.data(), this->get_handle_ptr());
690690
}
@@ -1015,7 +1015,7 @@ struct program : MIGRAPHX_HANDLE_BASE(program)
10151015
return module{p_modu, this->share_handle()};
10161016
}
10171017

1018-
friend bool operator!=(const program& px, const program& py) { return !(px == py); }
1018+
friend bool operator!=(const program& px, const program& py) { return not(px == py); }
10191019
};
10201020

10211021
// options for migraphx file format options

src/apply_alpha_beta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ instruction_ref insert_apply_alpha_beta(module& m,
3939
auto a = args[0];
4040
auto b = args[1];
4141
auto input_type = a->get_shape().type();
42-
if(!float_equal(alpha.at<float>(0), 1.0))
42+
if(not float_equal(alpha.at<float>(0), 1.0))
4343
{
4444
auto alpha_literal = m.add_literal(alpha);
4545
a = insert_common_op(m, pos, migraphx::make_op("mul"), {alpha_literal, a});

src/eliminate_concat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void eliminate_concat::apply(module& m) const
6060
auto lens = ins->inputs().front()->get_shape().lens();
6161
auto concat_op = concat_opt.get_concat(ins->get_operator());
6262
std::size_t axis_index = tune_axis(lens.size(), concat_op.axis, concat_op.name());
63-
if(axis_index == 0 ||
63+
if(axis_index == 0 or
6464
std::all_of(lens.begin(), lens.begin() + axis_index, [](auto x) { return x == 1; }))
6565
{
6666
// Last input should be an allocation

src/eliminate_contiguous.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static bool try_compute_shape(instruction_ref ins,
7171
return (arg == ins) ? new_shape : arg->get_shape();
7272
});
7373

74-
if(!try_compute_shape(output, input_shapes, mods))
74+
if(not try_compute_shape(output, input_shapes, mods))
7575
{
7676
return false;
7777
}

src/file_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ T generic_read_file(const std::string& filename)
3939
is.seekg(0, std::ios::beg);
4040

4141
T buffer(size, 0);
42-
if(!is.read(&buffer[0], size))
42+
if(not is.read(&buffer[0], size))
4343
MIGRAPHX_THROW("Error reading file: " + filename);
4444
return buffer;
4545
}

src/include/migraphx/allocation_model.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct allocation_model
205205
template <typename PrivateDetailTypeErasedU = PrivateDetailTypeErasedT>
206206
private_detail_te_handle_type(
207207
PrivateDetailTypeErasedT value,
208-
typename std::enable_if<!std::is_reference<PrivateDetailTypeErasedU>::value,
208+
typename std::enable_if<not std::is_reference<PrivateDetailTypeErasedU>::value,
209209
int>::type* = nullptr) noexcept
210210
: private_detail_te_value(std::move(value))
211211
{
@@ -267,7 +267,7 @@ struct allocation_model
267267
private_detail_te_handle_base_type& private_detail_te_get_handle()
268268
{
269269
assert(private_detail_te_handle_mem_var != nullptr);
270-
if(!private_detail_te_handle_mem_var.unique())
270+
if(not private_detail_te_handle_mem_var.unique())
271271
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
272272
return *private_detail_te_handle_mem_var;
273273
}

0 commit comments

Comments
 (0)