[clang-tidy] bugprone-unchecked-optional-access aborted with some AOSP source files
This clang-tidy crash is reproducible with the latest clang-tidy source tree. I found it when testing revision r468909.
The clang-tidy stack dump points to bugprone-unchecked-optional-access check. If that check is disabled in the attached test.sh, clang-tidy will not abort.
To reproduce:
(1) unzip the attached test.zip file
(2) modify TIDY in test.sh to point to an clang-tidy built from r461044 or newer, when the bugprone-unchecked-optional-access check was added.
Note that attached test.i.cc is preprocessed from one of several AOSP source files that have this problem.
The clang-tidy aborted with stack dump:
1. <eof> parser at end of file
2. ASTMatcher: Processing 'bugprone-unchecked-optional-access' against:
FunctionDecl astc_codec::UnpackLogicalBlock : <device/generic/vulkan-cereal/third-party/astc-codec/src/decoder/logical_astc_block.cc:243:1, line:260:1>
--- Bound Nodes Begin ---
T - { RecordType : astc_codec::VoidExtentData
fun - { FunctionDecl astc_codec::UnpackLogicalBlock : <device/generic/vulkan-cereal/third-party/astc-codec/src/decoder/logical_astc_block.cc:243:1, line:260:1> }
--- Bound Nodes End ---
@llvm/issue-subscribers-clang-tidy
@chih-hung The revision numbers belong to the internal numbering scheme used within the Android/ChromeOS toolchains. Can you post SHAs instead?
r461044 is this commit:
commit 7e63a0d479dd3ccce20de5cddb0f138b537c08bb
Author: Yitzhak Mandelbaum <[email protected]>
Date: Sun Mar 6 19:01:46 2022 +0000
[clang-tidy] New check for safe usage of `std::optional` and like types.
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.
Differential Revision: https://reviews.llvm.org/D121120
Adding the author, @ymand, in case they have a quick idea on what's going on.
Not offhand, but any chance you can give me the full backtrace from the print out above before i try the attached zip file?
Attached the stack trace: stacktrace.zip
The code is hitting this assert: https://github.com/llvm/llvm-project/blob/2a0c0849747425b570561e6bd9869843131a880d/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp#L464
Its unclear, though, why the constructor decl is missing template arguments. Trying to figure that out now.
It turns out that this was matching on a different base::Optional, nested inside of another namespace. This base::Optional has simpler constructors which are not themselves templated and, therefore, violate the assertions we place around the intended base::Optional.
This issue was fixed by cd22e0d