[PATCH] D121120: [clang-tidy] New check for safe usage of `std::optional` and like types.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 5 07:19:45 PDT 2022


ymandel created this revision.
Herald added subscribers: carlosgalvezp, mgorny.
Herald added a project: All.
Eugene.Zelenko retitled this revision from "[clang][tidy] New check for safe usage of `std::optional` and like types." to "[clang-tidy] New check for safe usage of `std::optional` and like types.".
Eugene.Zelenko added reviewers: alexfh, aaron.ballman, njames93, LegalizeAdulthood.
Eugene.Zelenko edited projects, added clang-tools-extra; removed All.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
ymandel removed reviewers: alexfh, aaron.ballman, njames93, LegalizeAdulthood.
ymandel removed rG LLVM Github Monorepo as the repository for this revision.
ymandel removed subscribers: xazax.hun, Eugene.Zelenko, mgorny, carlosgalvezp.
ymandel added a comment.
ymandel updated this revision to Diff 413492.
ymandel updated this revision to Diff 413493.
ymandel updated this revision to Diff 427298.
ymandel added reviewers: sgatev, xazax.hun, aaron.ballman.
ymandel edited subscribers, added: kinu; removed: sgatev.
Herald added a subscriber: rnkovacs.
ymandel published this revision for review.
Herald added a subscriber: cfe-commits.

Thanks, Eugene -- I'm actually still working on this, filling out the FIXMEs, etc.   I uploaded it with `arc` as a draft and its clearly marked as such. Is there something more I should have done to preven it from being sent out?


ymandel added a comment.

Filled out all relevant docs/comments.


ymandel added a comment.

tweaks


ymandel added a comment.

Rebased



================
Comment at: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp:85
+
+  const auto ExitBlockState =
+      (*BlockToOutputState)[Context->getCFG().getExit().getBlockID()];
----------------
Please don't use `auto` if type is not spelled in same statement or iterator.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp:90
+
+  const auto ExitBlockLattice = ExitBlockState.getValue().Lattice;
+  for (const SourceLocation &Loc : ExitBlockLattice.getSourceLocations()) {
----------------
Ditto.


================
Comment at: clang-tools-extra/docs/ReleaseNotes.rst:109
+
+  FIXME: add release notes.
+
----------------
Please add description. Hint: should be same as first statement in documentation.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst:6
+
+FIXME: Describe what patterns does the check detect and why. Give examples.
----------------
Please do that.


This check verifies the safety of access to `std::optional` and related
types (including `absl::optional`). It is based on a corresponding Clang
Dataflow Analysis, which does most of the work. This check merely runs it and
converts its findings into diagnostics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121120

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/types/optional.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-unchecked-optional-access.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121120.427298.patch
Type: text/x-patch
Size: 21810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220505/bc8fad51/attachment-0001.bin>


More information about the cfe-commits mailing list