This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] A semicolon-separated list of the names of functions or methods to be considered as not having side-effects
ClosedPublic

Authored by zinovy.nis on Jan 1 2022, 10:20 AM.

Details

Summary

A semicolon-separated list of the names of functions or methods to be considered as not having side-effects was added for bugprone-assert-side-effect.
It can be used to exclude methods like iterator::begin/end from being considered as having side-effects.

Diff Detail

Event Timeline

zinovy.nis created this revision.Jan 1 2022, 10:20 AM
zinovy.nis requested review of this revision.Jan 1 2022, 10:20 AM

Fix clang-format issues.

Please mention new option in Release Notes (in changes in existing checks section).

Updated release notes.

Please mention new option in Release Notes (in changes in existing checks section).

Done

Eugene.Zelenko added inline comments.Jan 2 2022, 6:25 AM
clang-tools-extra/docs/ReleaseNotes.rst
169

Please separate with newline and use single back-ticks for options.

175–176

Ditto for back-ticks.

187

Ditto for back-ticks.

zinovy.nis updated this revision to Diff 396927.Jan 2 2022, 7:18 AM
zinovy.nis marked 3 inline comments as done.
carlosgalvezp added inline comments.Jan 2 2022, 1:33 PM
clang-tools-extra/docs/ReleaseNotes.rst
169

I introduced those double backticks due to review comments. As it turns out, single backticks are only for links, not for formatted text. Should they be brought back?

Eugene.Zelenko added inline comments.Jan 2 2022, 2:27 PM
clang-tools-extra/docs/ReleaseNotes.rst
169

Double back-ticks are for language constructs, single back-ticks for options, tool names, etc.

carlosgalvezp added inline comments.Jan 2 2022, 2:41 PM
clang-tools-extra/docs/ReleaseNotes.rst
169

Hm, I see. I think visually it's much more helpful to have options rendered as formatted code (just like you'd see them in the .clang-tidy file in a code editor) instead of in italic, which is what is rendered with single backticks.

carlosgalvezp added inline comments.Jan 3 2022, 1:45 AM
clang-tools-extra/docs/ReleaseNotes.rst
169

Also note that the main clang-tidy doc page uses doble backticks for options, not just language constructs, so I think it would be good to keep consistency with that:

https://raw.githubusercontent.com/llvm/llvm-project/main/clang-tools-extra/docs/clang-tidy/index.rst

Single backticks are used there only for links and together with the :program: keyword.

carlosgalvezp added inline comments.Jan 3 2022, 1:52 AM
clang-tools-extra/docs/ReleaseNotes.rst
169

Unless there's some documented style convention that says otherwise, of course. I haven't found anything in the LLVM Coding Standards.

aaron.ballman added inline comments.Jan 5 2022, 6:11 AM
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
36–47

Instead of using "Exception" here, can we rename slightly? Functions can have lists of exceptions (dynamic exception specifications are a thing in C++), so the use of "exception" can be somewhat confusing, but I think something like IgnoredFunctionList and IgnoredFunctions would be an improvement.

zinovy.nis updated this revision to Diff 398408.EditedJan 9 2022, 2:14 AM
  • FunctionException -> IgnoredFunctions
  • Fixed double ticks in rst docs.
zinovy.nis updated this revision to Diff 398409.Jan 9 2022, 2:16 AM
zinovy.nis updated this revision to Diff 398410.
zinovy.nis marked 5 inline comments as done.
zinovy.nis marked an inline comment as done.
aaron.ballman added inline comments.Jan 11 2022, 6:29 AM
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
60–64

This doesn't seem quite right to me (test coverage would help) in the case where the user is specifying a (potentially partially) qualified function name. e.g., imagine an IgnoredFunctions list of my::fancy_func,::other_func,yet::another_func where my is a namespace containing a function named fancy_func, and yet is a class with a static function named another_func. I think this code will only consider the name of the function itself, but not any part of its qualified name.

I think we typically implement function name exclusions via the matchesAnyListedName() AST matcher, as in: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp#L92

clang-tools-extra/docs/ReleaseNotes.rst
171–172
clang-tools-extra/docs/clang-tidy/checks/bugprone-assert-side-effect.rst
27

This doesn't document whether the names can be qualified or not, or whether the names have to have an exact match instead of a regex match.

clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
99

FWIW, I think this can be confusing in practice; the function called is ::MyClass:badButIgnoredFunc(). Further, if I had a global function named badButIgnoredFunc() it would *also* be ignored and I'd have no way to configure to distinguish between the two.

  • Support regexp for list of ignored functions.
zinovy.nis marked 4 inline comments as done.Jan 15 2022, 9:34 AM
zinovy.nis added inline comments.
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
60–64

Thanks a lot!
Done.

BTW, now we have "," separator for macros and ";" for ignored functions. Doesn't sound reasonable. What do you think?

clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
99

Added a new test case for it.

zinovy.nis retitled this revision from [clang-tidy] A comma-separated list of the names of functions or methods to be considered as not having side-effects to [clang-tidy] A semicolon-separated list of the names of functions or methods to be considered as not having side-effects.Jan 15 2022, 9:52 AM
zinovy.nis edited the summary of this revision. (Show Details)
zinovy.nis marked 2 inline comments as done.

Any other comments?

aaron.ballman added inline comments.Jan 20 2022, 12:17 PM
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
60–64
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
13

I don't think this included is needed?

clang-tools-extra/docs/ReleaseNotes.rst
171–172

I think this comment is still not done yet.

  • Remove unused include.
  • Update release notes.
zinovy.nis marked 3 inline comments as done.Jan 22 2022, 3:35 AM
aaron.ballman accepted this revision.Jan 25 2022, 6:49 AM

LGTM aside from a nit in the documentation.

clang-tools-extra/docs/ReleaseNotes.rst
172
This revision is now accepted and ready to land.Jan 25 2022, 6:49 AM
zinovy.nis marked an inline comment as done.Jan 25 2022, 10:08 AM
zinovy.nis added inline comments.
clang-tools-extra/docs/ReleaseNotes.rst
172

Thanks!

Fixed and pushed.