Unverified Commit a359d2c8 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Update to Cppcheck 2.11 (#1914)

parent 6dfdf24a
...@@ -228,14 +228,12 @@ rocm_enable_cppcheck( ...@@ -228,14 +228,12 @@ rocm_enable_cppcheck(
shadowVar shadowVar
shadowVariable shadowVariable
unsafeClassDivZero unsafeClassDivZero
# Disable because of too many FPs
arithOperationsOnVoidPointer
definePrefix:*test/include/test.hpp definePrefix:*test/include/test.hpp
ctuOneDefinitionRuleViolation:*test/* ctuOneDefinitionRuleViolation:*test/*
useSmartPointer:*src/api/api.cpp useSmartPointer:*src/api/api.cpp
useSmartPointer:*make_shared_array.hpp useSmartPointer:*make_shared_array.hpp
constParameter:*src/targets/gpu/*.cpp
constParameter:*src/targets/gpu/*.hpp
# Suppress mlir_conv.cpp since this file will be deleted
*:*src/targets/gpu/mlir_conv.cpp
FORCE FORCE
INCONCLUSIVE INCONCLUSIVE
RULE_FILE RULE_FILE
...@@ -252,10 +250,13 @@ rocm_enable_cppcheck( ...@@ -252,10 +250,13 @@ rocm_enable_cppcheck(
${CMAKE_CURRENT_SOURCE_DIR}/src/targets/gpu/kernels/include ${CMAKE_CURRENT_SOURCE_DIR}/src/targets/gpu/kernels/include
${CMAKE_CURRENT_SOURCE_DIR}/test/include ${CMAKE_CURRENT_SOURCE_DIR}/test/include
DEFINE DEFINE
MIGRAPHX_MLIR=1
CPPCHECK=1 CPPCHECK=1
__device__= __device__=
__host__= __host__=
__global__= __global__=
UNDEFINE
MIGRAPHX_USE_CLANG_TIDY
) )
enable_testing() enable_testing()
......
...@@ -107,6 +107,24 @@ ...@@ -107,6 +107,24 @@
<summary>Use make_shared or make_unique instead of new</summary> <summary>Use make_shared or make_unique instead of new</summary>
</message> </message>
</rule> </rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[ [^\(,;{}:]+ \w+ && (\w+|\(|\+|\-|\*)]]></pattern>
<message>
<id>UseNamedLogicOperator</id>
<severity>style</severity>
<summary>Use 'and' instead of &&</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[ (if|while) \([^\)&]+&& ]]></pattern>
<message>
<id>UseNamedLogicOperator</id>
<severity>style</severity>
<summary>Use 'and' instead of &&</summary>
</message>
</rule>
<rule> <rule>
<tokenlist>raw</tokenlist> <tokenlist>raw</tokenlist>
<pattern><![CDATA[ \|\| ]]></pattern> <pattern><![CDATA[ \|\| ]]></pattern>
......
...@@ -25,6 +25,6 @@ ROCmSoftwarePlatform/rocm-recipes ...@@ -25,6 +25,6 @@ ROCmSoftwarePlatform/rocm-recipes
facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake
ccache@v4.1 -DENABLE_TESTING=OFF ccache@v4.1 -DENABLE_TESTING=OFF
pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11 pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11
danmar/cppcheck@2.9 -DHAVE_RULES=1 danmar/cppcheck@bb2711c22a0be09efe7f1a8da3030876471026c8 -DHAVE_RULES=1 # 2.11
RadeonOpenCompute/rocm-cmake@027404a8326da6e7e9338e0b81f9428660190724 --build RadeonOpenCompute/rocm-cmake@027404a8326da6e7e9338e0b81f9428660190724 --build
-f requirements.txt -f requirements.txt
...@@ -114,7 +114,7 @@ int main(int argc, char** argv) ...@@ -114,7 +114,7 @@ int main(int argc, char** argv)
char* getCmdOption(char** begin, char** end, const std::string& option) char* getCmdOption(char** begin, char** end, const std::string& option)
{ {
char** itr = std::find(begin, end, option); char** itr = std::find(begin, end, option);
if(itr != end && ++itr != end) if(itr != end and ++itr != end)
{ {
return *itr; return *itr;
} }
......
...@@ -161,7 +161,7 @@ int main(int argc, char** argv) ...@@ -161,7 +161,7 @@ int main(int argc, char** argv)
auto num_results = auto num_results =
std::accumulate(lengths.begin(), lengths.end(), 1, std::multiplies<size_t>()); std::accumulate(lengths.begin(), lengths.end(), 1, std::multiplies<size_t>());
float* results = reinterpret_cast<float*>(outputs[0].data()); float* results = reinterpret_cast<float*>(outputs[0].data());
float* max = std::max_element(results, results + num_results); const float* max = std::max_element(results, results + num_results);
int answer = max - results; int answer = max - results;
std::cout << std::endl std::cout << std::endl
...@@ -192,12 +192,12 @@ void read_nth_digit(const int n, std::vector<float>& digit) ...@@ -192,12 +192,12 @@ void read_nth_digit(const int n, std::vector<float>& digit)
for(int i = 0; i < HEIGHT * WIDTH; ++i) for(int i = 0; i < HEIGHT * WIDTH; ++i)
{ {
unsigned char temp = 0; unsigned char temp = 0;
file.read((char*)&temp, sizeof(temp)); file.read(reinterpret_cast<char*>(&temp), sizeof(temp));
if(d == n) if(d == n)
{ {
float data = temp / 255.0; float data = temp / 255.0;
digit.push_back(data); digit.push_back(data);
std::cout << SYMBOLS[(int)(data * 10) % 11]; std::cout << SYMBOLS[static_cast<int>(data * 10) % 11];
if((i + 1) % WIDTH == 0) if((i + 1) % WIDTH == 0)
std::cout << std::endl; std::cout << std::endl;
} }
......
...@@ -899,7 +899,7 @@ migraphx_dynamic_dimensions_assign_to(migraphx_dynamic_dimensions_t output, ...@@ -899,7 +899,7 @@ migraphx_dynamic_dimensions_assign_to(migraphx_dynamic_dimensions_t output,
extern "C" migraphx_status extern "C" migraphx_status
migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions, migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions,
const_migraphx_dynamic_dimension_t* ptr, const const_migraphx_dynamic_dimension_t* ptr,
size_t size) size_t size)
{ {
auto api_error_result = migraphx::try_([&] { auto api_error_result = migraphx::try_([&] {
...@@ -1432,7 +1432,7 @@ extern "C" migraphx_status migraphx_instructions_assign_to(migraphx_instructions ...@@ -1432,7 +1432,7 @@ extern "C" migraphx_status migraphx_instructions_assign_to(migraphx_instructions
} }
extern "C" migraphx_status migraphx_instructions_create(migraphx_instructions_t* instructions, extern "C" migraphx_status migraphx_instructions_create(migraphx_instructions_t* instructions,
const_migraphx_instruction_t* ptr, const const_migraphx_instruction_t* ptr,
size_t size) size_t size)
{ {
auto api_error_result = migraphx::try_([&] { auto api_error_result = migraphx::try_([&] {
......
...@@ -209,7 +209,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimensions_assign_to( ...@@ -209,7 +209,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimensions_assign_to(
MIGRAPHX_C_EXPORT migraphx_status MIGRAPHX_C_EXPORT migraphx_status
migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions, migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions,
const_migraphx_dynamic_dimension_t* ptr, const const_migraphx_dynamic_dimension_t* ptr,
size_t size); size_t size);
MIGRAPHX_C_EXPORT migraphx_status MIGRAPHX_C_EXPORT migraphx_status
...@@ -377,7 +377,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_assign_to( ...@@ -377,7 +377,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_assign_to(
migraphx_instructions_t output, const_migraphx_instructions_t input); migraphx_instructions_t output, const_migraphx_instructions_t input);
MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_create( MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_create(
migraphx_instructions_t* instructions, const_migraphx_instruction_t* ptr, size_t size); migraphx_instructions_t* instructions, const const_migraphx_instruction_t* ptr, size_t size);
MIGRAPHX_C_EXPORT migraphx_status migraphx_modules_destroy(migraphx_modules_t modules); MIGRAPHX_C_EXPORT migraphx_status migraphx_modules_destroy(migraphx_modules_t modules);
......
...@@ -79,7 +79,8 @@ def dynamic_dimension(h): ...@@ -79,7 +79,8 @@ def dynamic_dimension(h):
def dynamic_dimensions(h): def dynamic_dimensions(h):
h.constructor( h.constructor(
'create', 'create',
api.params(ptr='const_migraphx_dynamic_dimension_t*', size='size_t'), api.params(ptr='const const_migraphx_dynamic_dimension_t*',
size='size_t'),
fname='migraphx::to_obj_vector<const_migraphx_dynamic_dimension_t>') fname='migraphx::to_obj_vector<const_migraphx_dynamic_dimension_t>')
h.method('size', returns='size_t') h.method('size', returns='size_t')
h.method('get', h.method('get',
...@@ -215,7 +216,7 @@ def instruction(h): ...@@ -215,7 +216,7 @@ def instruction(h):
def instructions(h): def instructions(h):
h.constructor( h.constructor(
'create', 'create',
api.params(ptr='const_migraphx_instruction_t*', size='size_t'), api.params(ptr='const const_migraphx_instruction_t*', size='size_t'),
fname='migraphx::to_obj_vector<const_migraphx_instruction_t>') fname='migraphx::to_obj_vector<const_migraphx_instruction_t>')
......
...@@ -338,7 +338,7 @@ struct argument_parser ...@@ -338,7 +338,7 @@ struct argument_parser
MIGRAPHX_DRIVER_STATIC auto file_exist() MIGRAPHX_DRIVER_STATIC auto file_exist()
{ {
return validate([](auto&, auto&, auto& params) { return validate([](auto&, auto&, const auto& params) {
if(params.empty()) if(params.empty())
throw std::runtime_error("No argument passed."); throw std::runtime_error("No argument passed.");
if(not fs::exists(params.back())) if(not fs::exists(params.back()))
...@@ -348,13 +348,12 @@ struct argument_parser ...@@ -348,13 +348,12 @@ struct argument_parser
MIGRAPHX_DRIVER_STATIC auto matches(const std::unordered_set<std::string>& names) MIGRAPHX_DRIVER_STATIC auto matches(const std::unordered_set<std::string>& names)
{ {
return validate([=](auto&, auto&, auto& params) { return validate([=](auto&, auto&, const auto& params) {
for(const auto& p : params) auto invalid_param = std::find_if(
{ params.begin(), params.end(), [&](const auto& p) { return names.count(p) == 0; });
if(names.count(p) == 0) if(invalid_param != params.end())
throw std::runtime_error("Invalid argument: " + p + ". Valid arguments are {" + throw std::runtime_error("Invalid argument: " + *invalid_param +
to_string_range(names) + "}"); ". Valid arguments are {" + to_string_range(names) + "}");
}
}); });
} }
......
...@@ -41,7 +41,7 @@ static literal get_scalar(instruction_ref ins) ...@@ -41,7 +41,7 @@ static literal get_scalar(instruction_ref ins)
if(ins->name() == "contiguous") if(ins->name() == "contiguous")
return get_scalar(ins->inputs().front()); return get_scalar(ins->inputs().front());
const auto& s = ins->get_shape(); const auto& s = ins->get_shape();
if(s.elements() != 1 && not(s.scalar())) if(s.elements() != 1 and not(s.scalar()))
return {}; return {};
if(not ins->can_eval()) if(not ins->can_eval())
return {}; return {};
......
...@@ -52,7 +52,7 @@ struct fused_reduce ...@@ -52,7 +52,7 @@ struct fused_reduce
{ {
if(mods.size() != 1) if(mods.size() != 1)
MIGRAPHX_THROW("should have one submodule."); MIGRAPHX_THROW("should have one submodule.");
auto* sm = mods.front(); const auto* sm = mods.front();
if(sm->get_output_shapes().size() != 1) if(sm->get_output_shapes().size() != 1)
MIGRAPHX_THROW("Only one output supported"); MIGRAPHX_THROW("Only one output supported");
auto names = sm->get_parameter_names(); auto names = sm->get_parameter_names();
...@@ -143,7 +143,7 @@ insert_module_in_submodule(module_ref sm, ...@@ -143,7 +143,7 @@ insert_module_in_submodule(module_ref sm,
} }
static std::vector<instruction_ref> static std::vector<instruction_ref>
find_inputs(module_ref sm, find_inputs(const_module_ref sm,
const module& parent, const module& parent,
const std::unordered_map<instruction_ref, instruction_ref>& map_ins) const std::unordered_map<instruction_ref, instruction_ref>& map_ins)
{ {
......
...@@ -100,8 +100,7 @@ inline size_t levenshtein_distance(const std::string& s1, const std::string& s2) ...@@ -100,8 +100,7 @@ inline size_t levenshtein_distance(const std::string& s1, const std::string& s2)
std::vector<size_t> d(l2 + 1); std::vector<size_t> d(l2 + 1);
for(size_t j = 1; j <= l2; j++) std::iota(d.begin(), d.end(), 0);
d[j] = j;
for(size_t i = 1; i <= l1; i++) for(size_t i = 1; i <= l1; i++)
{ {
......
...@@ -82,7 +82,7 @@ struct convolution ...@@ -82,7 +82,7 @@ struct convolution
const auto input_ndim = inputs[0].ndim(); const auto input_ndim = inputs[0].ndim();
const auto padding_size = padding.size(); const auto padding_size = padding.size();
if(input_ndim != padding_size / 2 + 2 && input_ndim != padding_size + 2) if(input_ndim != padding_size / 2 + 2 and input_ndim != padding_size + 2)
{ {
MIGRAPHX_THROW("CONVOLUTION: input and attribute size mismatch!"); MIGRAPHX_THROW("CONVOLUTION: input and attribute size mismatch!");
} }
......
...@@ -71,7 +71,7 @@ struct if_op ...@@ -71,7 +71,7 @@ struct if_op
std::unordered_map<std::string, argument> params; std::unordered_map<std::string, argument> params;
std::set<std::string> pnames; std::set<std::string> pnames;
for(const auto& smod : mods) for(const_module_ref smod : mods)
{ {
auto names = smod->get_parameter_names(); auto names = smod->get_parameter_names();
pnames.insert(names.begin(), names.end()); pnames.insert(names.begin(), names.end());
......
...@@ -59,7 +59,7 @@ struct loop ...@@ -59,7 +59,7 @@ struct loop
MIGRAPHX_THROW("LOOP: operator should have one submodule."); MIGRAPHX_THROW("LOOP: operator should have one submodule.");
} }
const auto& mod = mods.front(); const_module_ref mod = mods.front();
auto mod_out_shapes = mod->get_output_shapes(); auto mod_out_shapes = mod->get_output_shapes();
auto dep_param_num = inputs.size() - 2; auto dep_param_num = inputs.size() - 2;
......
...@@ -389,7 +389,7 @@ void instruction::print(std::ostream& os, ...@@ -389,7 +389,7 @@ void instruction::print(std::ostream& os,
if(not ins->module_inputs().empty()) if(not ins->module_inputs().empty())
{ {
std::string delim = ", ["; std::string delim = ", [";
for(auto&& mod_arg : ins->module_inputs()) for(const const_module_ref& mod_arg : ins->module_inputs())
{ {
os << delim << mod_arg->name(); os << delim << mod_arg->name();
delim = ", "; delim = ", ";
......
...@@ -873,12 +873,11 @@ module::print_py(std::ostream& os, ...@@ -873,12 +873,11 @@ module::print_py(std::ostream& os,
if(ins->name() == "@literal") if(ins->name() == "@literal")
{ {
os << mname << ".add_literal("; os << mname << ".add_literal(";
bool use_abs = false; const bool use_abs = false;
ins->get_literal().visit([&](auto v) {
use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; });
});
// Disable abs for now // Disable abs for now
use_abs = false; // ins->get_literal().visit([&](auto v) {
// use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; });
// });
if(use_abs) if(use_abs)
os << "migraphx.abs_literal("; os << "migraphx.abs_literal(";
os << "migraphx.generate_argument("; os << "migraphx.generate_argument(";
......
...@@ -55,9 +55,6 @@ struct parse_constant_of_shape : op_parser<parse_constant_of_shape> ...@@ -55,9 +55,6 @@ struct parse_constant_of_shape : op_parser<parse_constant_of_shape>
l_val = literal({shape::float_type, {1}, {0}}, {0.0f}); l_val = literal({shape::float_type, {1}, {0}}, {0.0f});
} }
// input is empty, output is a scalar
auto type = l_val.get_shape().type();
if(args.empty()) if(args.empty())
{ {
MIGRAPHX_THROW("ConstantOfShape : must have 1 input!"); MIGRAPHX_THROW("ConstantOfShape : must have 1 input!");
...@@ -65,6 +62,8 @@ struct parse_constant_of_shape : op_parser<parse_constant_of_shape> ...@@ -65,6 +62,8 @@ struct parse_constant_of_shape : op_parser<parse_constant_of_shape>
else else
{ {
migraphx::shape s; migraphx::shape s;
// input is empty, output is a scalar
auto type = l_val.get_shape().type();
// empty input tensor, output is a scalar // empty input tensor, output is a scalar
if(args[0]->get_shape().elements() == 0) if(args[0]->get_shape().elements() == 0)
{ {
......
...@@ -223,7 +223,7 @@ void program::compile(const std::vector<target>& targets, std::vector<compile_op ...@@ -223,7 +223,7 @@ void program::compile(const std::vector<target>& targets, std::vector<compile_op
// Gather all the target roots // Gather all the target roots
std::unordered_multimap<std::size_t, module_ref> roots; std::unordered_multimap<std::size_t, module_ref> roots;
auto mods = this->get_modules(); auto mods = this->get_modules();
for(auto* mod : mods) for(const auto* mod : mods)
{ {
for(const auto& ins : *mod) for(const auto& ins : *mod)
{ {
...@@ -548,7 +548,7 @@ std::vector<argument> program::eval(parameter_map params, execution_environment ...@@ -548,7 +548,7 @@ std::vector<argument> program::eval(parameter_map params, execution_environment
ins_out[x] = ss.str(); ins_out[x] = ss.str();
}); });
ret = generic_eval(*this, contexts, std::move(params), [&](instruction_ref ins, auto f) { ret = generic_eval(*this, contexts, std::move(params), [&](instruction_ref ins, auto f) {
auto& ctx = contexts[ins->get_target_id()]; const auto& ctx = contexts[ins->get_target_id()];
ctx.finish(); ctx.finish();
std::cout << "Run instruction: " << ins_out.at(ins) << std::endl; std::cout << "Run instruction: " << ins_out.at(ins) << std::endl;
timer t{}; timer t{};
...@@ -728,7 +728,7 @@ static void mod_from_val(module_ref mod, ...@@ -728,7 +728,7 @@ static void mod_from_val(module_ref mod,
std::back_inserter(module_inputs), std::back_inserter(module_inputs),
[&](const value& i) { return map_mods.at(i.to<std::string>()); }); [&](const value& i) { return map_mods.at(i.to<std::string>()); });
for(auto& smod : module_inputs) for(const auto& smod : module_inputs)
{ {
mod_from_val(smod, v, instructions, map_mods); mod_from_val(smod, v, instructions, map_mods);
} }
...@@ -1186,7 +1186,7 @@ void program::remove_unused_modules() ...@@ -1186,7 +1186,7 @@ void program::remove_unused_modules()
std::vector<module*> unused; std::vector<module*> unused;
generic_get_unused_modules( generic_get_unused_modules(
impl->modules, generic_get_modules(this->get_main_module()), std::back_inserter(unused)); impl->modules, generic_get_modules(this->get_main_module()), std::back_inserter(unused));
for(auto* m : unused) for(const auto* m : unused)
this->remove_module(m->name()); this->remove_module(m->name());
} }
......
...@@ -48,6 +48,7 @@ struct sqlite_impl ...@@ -48,6 +48,7 @@ struct sqlite_impl
template <class F> template <class F>
void exec(const char* sql, F f) void exec(const char* sql, F f)
{ {
// cppcheck-suppress constParameterPointer
auto callback = [](void* obj, auto... xs) -> int { auto callback = [](void* obj, auto... xs) -> int {
try try
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment