Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add used-after-move checking to clang-tidy #1566

Merged

Conversation

mapleFU
Copy link
Member

@mapleFU mapleFU commented Jul 8, 2023

clang-tidy has a bugprone checkings under: https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html . I've checked all bugprone-, the result contains many style fixing.

This patch only adds a bugprone-use-after-move into clang-tidy. It detect a used-after-move in src/storage/compaction_checker.cc, moving rocksdb::Slice doesn't clear it contents.

And maybe we can enable all bugprone-* and do some NOLINT or style fixing in the future?

PragmaTwice
PragmaTwice previously approved these changes Jul 8, 2023
@PragmaTwice
Copy link
Member

PragmaTwice commented Jul 8, 2023

And maybe we can enable all bugprone-* and do some NOLINT or style fixing in the future?

We need to specify the concrete name of checkers to prevent different checkers in different version of clang-tidy.

best_start_key = start_key;
start_key.clear();
best_stop_key = stop_key;
stop_key.clear();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@git-hulk by the way, would you mind check the logic here? Previously, it will move rocksdb::Slice, however, moving rocksdb::Slice will not clear it, so it's same as copy. L:108 has:

    if (start_key.empty() || stop_key.empty()) continue;

So it might break the logic. I've check the compaction, and personally I guess clear it is ok. Would you mind take a look?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's good to use clear here.

git-hulk
git-hulk previously approved these changes Jul 8, 2023
.clang-tidy Outdated
@@ -1,5 +1,5 @@
# refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html
Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param, readability-avoid-const-params-in-decls, readability-const-return-type, readability-convert-member-functions-to-static, readability-make-member-function-const, readability-redundant-access-specifiers, readability-redundant-control-flow, readability-redundant-declaration, readability-redundant-member-init, readability-redundant-string-cstr, readability-redundant-string-init, readability-simplify-boolean-expr, readability-simplify-subscript-expr, readability-string-compare, readability-identifier-naming, cppcoreguidelines-avoid-goto
Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param, readability-avoid-const-params-in-decls, readability-const-return-type, readability-convert-member-functions-to-static, readability-make-member-function-const, readability-redundant-access-specifiers, readability-redundant-control-flow, readability-redundant-declaration, readability-redundant-member-init, readability-redundant-string-cstr, readability-redundant-string-init, readability-simplify-boolean-expr, readability-simplify-subscript-expr, readability-string-compare, readability-identifier-naming, cppcoreguidelines-avoid-goto, bugprone-use-after-move

WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, google-*, performance-*, cppcoreguidelines-*, modernize-*, readability-*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add this rule to WarningsAsErrors also? Or it already causes errors?

Copy link
Member Author

@mapleFU mapleFU Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes moved after use is well-defined, like vector2_(std::move(vector1)); would make sure that after move constructor, vector1 is empty. But it's "bugprone", most of times, use after move would cause bugs.
But I think we can move this to WarningsAsErrors, because there're no move-after-used in kvrocks after this patch

@mapleFU mapleFU dismissed stale reviews from git-hulk and PragmaTwice via eddf625 July 8, 2023 16:19
@PragmaTwice PragmaTwice changed the title [Tools] clang-tidy: add used-after-move checking Add used-after-move checking to clang-tidy Jul 9, 2023
@PragmaTwice PragmaTwice added the A-ci area ci label Jul 9, 2023
@PragmaTwice PragmaTwice merged commit e2d637c into apache:unstable Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ci area ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants