Enable misc clang-tidy checks (#110283)

This PR enables the misc-XX checks in clang-tidy. Meanwhile, I excluded some of them that require a lot of code changes and have no immediate benefits. Some additional fixes and suppression were also given.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/110283
Approved by: https://github.com/albanD
This commit is contained in:
cyy
2023-09-30 10:39:52 +00:00
committed by PyTorch MergeBot
parent 2ead6c2f6e
commit d0ad848aa5
13 changed files with 22 additions and 7 deletions

View File

@ -30,8 +30,13 @@ cppcoreguidelines-*,
-facebook-hte-RelativeInclude,
hicpp-exception-baseclass,
hicpp-avoid-goto,
misc-unused-alias-decls,
misc-unused-using-decls,
misc-*,
-misc-const-correctness,
-misc-use-anonymous-namespace,
-misc-unused-parameters,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-confusable-identifiers,
modernize-*,
-modernize-concat-nested-namespaces,
-modernize-macro-to-enum,

View File

@ -44,7 +44,7 @@ void ThrowEnforceNotMet(
if (FLAGS_caffe2_use_fatal_for_enforce) {
LOG(FATAL) << e.msg();
}
throw e;
throw std::move(e);
}
void ThrowEnforceNotMet(

View File

@ -79,8 +79,7 @@ void NUMAMove(void* ptr, size_t size, int numa_node_id) {
uintptr_t page_start_ptr =
((reinterpret_cast<uintptr_t>(ptr)) & ~(getpagesize() - 1));
// NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions)
// NOLINTNEXTLINE(bugprone-narrowing-conversions)
// NOLINTNEXTLINE(*-conversions)
ptrdiff_t offset = reinterpret_cast<uintptr_t>(ptr) - page_start_ptr;
// Avoid extra dynamic allocation and NUMA api calls
AT_ASSERT(

View File

@ -247,6 +247,7 @@ PyTypeObject THPGeneratorType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */

View File

@ -627,6 +627,7 @@ PyTypeObject THPStorageMetaType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */
@ -670,6 +671,7 @@ PyTypeObject THPStorageType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */

View File

@ -130,6 +130,7 @@ PyTypeObject THPStreamType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */

View File

@ -216,6 +216,7 @@ PyTypeObject* _initFunctionPyTypeObject(
const char* name,
PyGetSetDef* function_properties,
PyMethodDef* function_methods) {
// NOLINTNEXTLINE(misc-redundant-expression)
type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC;
type.tp_name = name;
type.tp_basicsize = sizeof(THPCppFunction);

View File

@ -422,6 +422,7 @@ PyTypeObject THPEngineType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */

View File

@ -68,7 +68,7 @@ namespace {
void throw_python_error() {
python_error err;
err.persist();
throw err;
throw std::move(err);
}
} // namespace
@ -1557,6 +1557,7 @@ PyTypeObject THPFunctionType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC, /* tp_flags */
nullptr, /* tp_doc */

View File

@ -131,6 +131,7 @@ PyTypeObject THPLegacyVariableType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */

View File

@ -1666,6 +1666,7 @@ PyTypeObject THPVariableMetaType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
nullptr, /* tp_doc */
nullptr, /* tp_traverse */
@ -1711,6 +1712,7 @@ PyTypeObject THPVariableType = {
nullptr, /* tp_getattro */
nullptr, /* tp_setattro */
nullptr, /* tp_as_buffer */
// NOLINTNEXTLINE(misc-redundant-expression)
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC, /* tp_flags */
nullptr, /* tp_doc */

View File

@ -182,6 +182,7 @@ static PyTypeObject metaclass = {
};
static void py_initialize_metaclass(PyTypeObject& metaclass) {
// NOLINTNEXTLINE(misc-redundant-expression)
metaclass.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
metaclass.tp_methods = metaclass_methods;
metaclass.tp_getset = metaclass_properties;

View File

@ -791,7 +791,7 @@ static bool is_int_list(
// Make sure none of the later arguments are SymInt
// NB: do NOT check that the later arguments are ints, as this is
// BC-breaking for FX
for (int i = 1; i < len; i++) {
for (Py_ssize_t i = 1; i < len; i++) {
if (torch::is_symint(
py::reinterpret_steal<py::object>(PySequence_GetItem(obj, i)))) {
if (failed_idx != nullptr) {