llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] bugprone-unchecked-optional-access aborted with some AOSP source files

Open chih-hung opened this issue 4 years ago • 9 comments

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 ---

test.zip

chih-hung avatar Aug 09 '22 22:08 chih-hung

@llvm/issue-subscribers-clang-tidy

llvmbot avatar Aug 09 '22 22:08 llvmbot

@chih-hung The revision numbers belong to the internal numbering scheme used within the Android/ChromeOS toolchains. Can you post SHAs instead?

pirama-arumuga-nainar avatar Aug 09 '22 22:08 pirama-arumuga-nainar

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

chih-hung avatar Aug 09 '22 23:08 chih-hung

Adding the author, @ymand, in case they have a quick idea on what's going on.

pirama-arumuga-nainar avatar Aug 09 '22 23:08 pirama-arumuga-nainar

Not offhand, but any chance you can give me the full backtrace from the print out above before i try the attached zip file?

ymand avatar Aug 10 '22 20:08 ymand

Attached the stack trace: stacktrace.zip

chih-hung avatar Aug 10 '22 21:08 chih-hung

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.

ymand avatar Apr 11 '23 15:04 ymand

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.

ymand avatar Apr 14 '23 14:04 ymand

This issue was fixed by cd22e0d

ymand avatar Mar 07 '24 19:03 ymand