llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.08k forks source link

clang-tidy `bugprone-unchecked-optional-access`: segmentation fault #111003

Open scarf005 opened 1 month ago

scarf005 commented 1 month ago

Repo and command

https://github.com/cataclysmbnteam/Cataclysm-BN/tree/305368a591cdf3f97d46332eb99cf88871f3949d

clang-tidy --enable-check-profile src/iexamine.cpp

(happens without plugins)

clang-tidy version

clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 18.1.8
  Optimized build.

Stacktrace

./build-scripts/clang-tidy-wrapper.sh: 줄 12: 1435352 세그멘테이션 오류 (코어 덤프됨) clang-tidy --load=$PLUGIN --enable-check-profile --store-check-profile=clang-tidy-trace "$@"
+ PLUGIN=build/tools/clang-tidy-plugin/libCataAnalyzerPlugin.so
+ clang-tidy --load=build/tools/clang-tidy-plugin/libCataAnalyzerPlugin.so --enable-check-profile --store-check-profile=clang-tidy-trace -quiet src/iexamine.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-tidy --load=build/tools/clang-tidy-plugin/libCataAnalyzerPlugin.so --enable-check-profile --store-check-profile=clang-tidy-trace -quiet src/active_tile_data.cpp
1.      <eof> parser at end of file
2.      ASTMatcher: Processing 'bugprone-unchecked-optional-access' against:
        FunctionDecl veh_pointer_or_null : </run/media/home/scarf/repo/cata/Cataclysm/src/vpart_position.h:156:1, line:159:1>
--- Bound Nodes Begin ---
    T - { RecordType : vpart_position }
    fun - { FunctionDecl veh_pointer_or_null : </run/media/home/scarf/repo/cata/Cataclysm/src/vpart_position.h:156:1, line:159:1> }
--- Bound Nodes End ---
3.      runTypeErasedDataflowAnalysis
Decl:
FunctionDecl 0x7f1610dc36f8 </run/media/home/scarf/repo/cata/Cataclysm/src/vpart_position.h:156:1, line:159:1> line:156:17 veh_pointer_or_null 'vehicle *(const optional_vpart_position &)' inline
|-ParmVarDecl 0x7f1610dc35e8 <col:38, col:69> col:69 used p 'const optional_vpart_position &'
`-CompoundStmt 0x7f1610dc4198 <line:157:1, line:159:1>
  `-ReturnStmt 0x7f1610dc4188 <line:158:5, col:32>
    `-ConditionalOperator 0x7f1610dc4158 <col:12, col:32> '::vehicle *'
      |-ImplicitCastExpr 0x7f1610dc4128 <col:12> 'bool' <UserDefinedConversion>
      | `-CXXMemberCallExpr 0x7f1610dc4108 <col:12> 'bool'
      |   `-MemberExpr 0x7f1610dc4010 <col:12> '<bound member function type>' .operator bool 0x7f1610e56710
      |     `-ImplicitCastExpr 0x7f1610dc3ff0 <col:12> 'const std::optional<vpart_position>' lvalue <UncheckedDerivedToBase (optional)>
      |       `-DeclRefExpr 0x7f1610dc37a8 <col:12> 'const optional_vpart_position' lvalue ParmVar 0x7f1610dc35e8 'p' 'const optional_vpart_position &'
      |-UnaryOperator 0x7f1610dc3fc0 <col:16, col:28> '::vehicle *' prefix '&' cannot overflow
      | `-CXXMemberCallExpr 0x7f1610dc3f68 <col:17, col:28> '::vehicle':'vehicle' lvalue
      |   `-MemberExpr 0x7f1610dc3f38 <col:17, col:20> '<bound member function type>' ->vehicle 0x7f1610e02d68
      |     `-CXXOperatorCallExpr 0x7f1610dc3f08 <col:17, col:18> 'const vpart_position *' '->'
      |       |-ImplicitCastExpr 0x7f1610dc3ef0 <col:18> 'const vpart_position *(*)() const noexcept' <FunctionToPointerDecay>
      |       | `-DeclRefExpr 0x7f1610dc3808 <col:18> 'const vpart_position *() const noexcept' lvalue CXXMethod 0x7f1610e55e58 'operator->' 'const vpart_position *() const noexcept'
      |       `-ImplicitCastExpr 0x7f1610dc37e8 <col:17> 'const std::optional<vpart_position>' lvalue <UncheckedDerivedToBase (optional)>
      |         `-DeclRefExpr 0x7f1610dc37c8 <col:17> 'const optional_vpart_position' lvalue ParmVar 0x7f1610dc35e8 'p' 'const optional_vpart_position &'
      `-ImplicitCastExpr 0x7f1610dc4140 <col:32> '::vehicle *' <NullToPointer>
        `-CXXNullPtrLiteralExpr 0x7f1610dc3fd8 <col:32> 'std::nullptr_t'
CFG:

 [B5 (ENTRY)]
   Succs (1): B4

 [B1]
   1: [B4.5] ? [B2.8] : [B3.2]
   2: return [B1.1];
   Preds (2): B2 B3
   Succs (1): B0

 [B2]
   1: operator->
   2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, const class vpart_position *(*)(void) const noexcept)
   3: p
   4: [B2.3] (ImplicitCastExpr, UncheckedDerivedToBase, const class std::optional<class vpart_position>)
   5: [B2.4] (OperatorCall)
   6: [B2.5]->vehicle
   7: [B2.6]()
   8: &[B2.7]
   Preds (1): B4
   Succs (1): B1

 [B3]
   1: nullptr
   2: [B3.1] (ImplicitCastExpr, NullToPointer, ::vehicle *)
   Preds (1): B4
   Succs (1): B1

 [B4]
   1: p
   2: [B4.1] (ImplicitCastExpr, UncheckedDerivedToBase, const class std::optional<class vpart_position>)
   3: [B4.2].operator bool
   4: [B4.2]
   5: [B4.4] (ImplicitCastExpr, UserDefinedConversion, _Bool)
   T: [B4.5] ? ... : ...
   Preds (1): B5
   Succs (2): B2 B3

 [B0 (EXIT)]
   Preds (1): B1

4.      transferCFGBlock: Element [B2.5]
Stmt:
CXXOperatorCallExpr 0x7f1610dc3f08 'const class vpart_position *' '->'
|-ImplicitCastExpr 0x7f1610dc3ef0 'const class vpart_position *(*)(void) const noexcept' <FunctionToPointerDecay>
| `-DeclRefExpr 0x7f1610dc3808 'const class vpart_position *(void) const noexcept' lvalue CXXMethod 0x7f1610e55e58 'operator->' 'const class vpart_position *(void) const noexcept'
`-ImplicitCastExpr 0x7f1610dc37e8 'const class std::optional<class vpart_position>' lvalue <UncheckedDerivedToBase (optional)>
  `-DeclRefExpr 0x7f1610dc37c8 'const optional_vpart_position':'const class optional_vpart_position' lvalue ParmVar 0x7f1610dc35e8 'p' 'const optional_vpart_position &'
 #0 0x00007f16168044fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM.so.18.1+0x6044fa)
 #1 0x00007f1616801ce4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM.so.18.1+0x601ce4)
 #2 0x00007f1616804c5b (/lib64/libLLVM.so.18.1+0x604c5b)
 #3 0x00007f1615c4fd00 __restore_rt (/lib64/libc.so.6+0x40d00)
 #4 0x00007f161f2e5c33 (/lib64/libclang-cpp.so.18.1+0x1ee5c33)
 #5 0x00007f161f2e5e68 (/lib64/libclang-cpp.so.18.1+0x1ee5e68)
 #6 0x00007f161f2e5d61 (/lib64/libclang-cpp.so.18.1+0x1ee5d61)
 #7 0x00007f161f2e6101 (/lib64/libclang-cpp.so.18.1+0x1ee6101)
 #8 0x00007f161f2e687b (/lib64/libclang-cpp.so.18.1+0x1ee687b)
 #9 0x000055a059eb9a66 (/usr/bin/clang-tidy+0x373a66)
#10 0x000055a059eb9473 (/usr/bin/clang-tidy+0x373473)
#11 0x00007f161f2c8836 (/lib64/libclang-cpp.so.18.1+0x1ec8836)
#12 0x00007f161f2c7fbc clang::dataflow::runTypeErasedDataflowAnalysis(clang::dataflow::ControlFlowContext const&, clang::dataflow::TypeErasedDataflowAnalysis&, clang::dataflow::Environment const&, std::function<void (clang::CFGElement const&, clang::dataflow::TypeErasedDataflowAnalysisState const&)>, int) (/lib64/libclang-cpp.so.18.1+0x1ec7fbc)
#13 0x000055a059eb80c9 clang::tidy::bugprone::UncheckedOptionalAccessCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/usr/bin/clang-tidy+0x3720c9)
#14 0x000055a05a414ed2 (/usr/bin/clang-tidy+0x8ceed2)
#15 0x000055a05a44a2bc clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/usr/bin/clang-tidy+0x9042bc)
#16 0x000055a05a414713 (/usr/bin/clang-tidy+0x8ce713)
#17 0x000055a05a4165eb (/usr/bin/clang-tidy+0x8d05eb)
#18 0x000055a05a44689b (/usr/bin/clang-tidy+0x90089b)
#19 0x000055a05a416f66 (/usr/bin/clang-tidy+0x8d0f66)
#20 0x000055a05a416613 (/usr/bin/clang-tidy+0x8d0613)
#21 0x000055a05a3e14aa clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/usr/bin/clang-tidy+0x89b4aa)
#22 0x00007f161fc538ec clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/lib64/libclang-cpp.so.18.1+0x28538ec)
#23 0x00007f161d9743e6 clang::ParseAST(clang::Sema&, bool, bool) (/lib64/libclang-cpp.so.18.1+0x5743e6)
#24 0x00007f161fc1c816 clang::FrontendAction::Execute() (/lib64/libclang-cpp.so.18.1+0x281c816)
#25 0x00007f161fb94520 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib64/libclang-cpp.so.18.1+0x2794520)
#26 0x00007f161fe31721 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/lib64/libclang-cpp.so.18.1+0x2a31721)
#27 0x000055a05ab6f02e (/usr/bin/clang-tidy+0x102902e)
#28 0x00007f161fe313e4 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/lib64/libclang-cpp.so.18.1+0x2a313e4)
#29 0x00007f161fe30164 clang::tooling::ToolInvocation::run() (/lib64/libclang-cpp.so.18.1+0x2a30164)
#30 0x00007f161fe33315 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/lib64/libclang-cpp.so.18.1+0x2a33315)
#31 0x000055a05ab6a3da clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) (/usr/bin/clang-tidy+0x10243da)
#32 0x000055a059d5b06c clang::tidy::clangTidyMain(int, char const**) (/usr/bin/clang-tidy+0x21506c)
#33 0x00007f1615c39088 __libc_start_call_main (/lib64/libc.so.6+0x2a088)
#34 0x00007f1615c3914b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14b)
#35 0x000055a059d57245 _start (/usr/bin/clang-tidy+0x211245)
EugeneZelenko commented 1 month ago

Could you please try 19 or main branch? https://godbolt.org should be helpful.