Skip to content

Commit

Permalink
Enable misc clang-tidy checks (pytorch#110283)
Browse files Browse the repository at this point in the history
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: pytorch#110283
Approved by: https://github.com/albanD
  • Loading branch information
cyyever authored and pytorchmergebot committed Sep 30, 2023
1 parent 2ead6c2 commit d0ad848
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion c10/util/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions c10/util/numa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/autograd/python_cpp_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/autograd/python_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion torch/csrc/autograd/python_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace {
void throw_python_error() {
python_error err;
err.persist();
throw err;
throw std::move(err);
}

} // namespace
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/autograd/python_legacy_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/autograd/python_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/tensor/python_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/utils/python_arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d0ad848

Please sign in to comment.