Skip to content

clang-tidy crash parsing OpenMP loop #49405

Closed as not planned
Closed as not planned
@jlaxson

Description

@jlaxson
Bugzilla Link 50061
Version unspecified
OS MacOS X

Extended Description

clang-tidy crashes when parsing a method containing an OpenMP parallel block with this stack trace:

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/jlaxson/Downloads/llvm-project/build/bin/clang-tidy -fix file.cpp --extra-arg=-v
1.	file.cpp:137:5: current parser token 'return'
2.	file.cpp:16:1: parsing struct/union/class body 'MyClass'
3.	file.cpp:72:37: parsing function body 'MyClass::MyMethod'
4.	file.cpp:72:37: in compound statement ('{}')
AddressSanitizer:DEADLYSIGNAL
=================================================================
==94711==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x00011464b473 bp 0x7ffee1718820 sp 0x7ffee1717e00 T0)
==94711==The signal is caused by a READ memory access.
==94711==Hint: address points to the zero page.
    #&#8203;0 0x11464b472 in checkOpenMPLoop(llvm::omp::Directive, clang::Expr*, clang::Expr*, clang::Stmt*, clang::Sema&, (anonymous namespace)::DSAStackTy&, llvm::SmallDenseMap<clang::ValueDecl const*, clang::Expr const*, 4u, llvm::DenseMapInfo<clang::ValueDecl const*>, llvm::detail::DenseMapPair<clang::ValueDecl const*, clang::Expr const*> >&, clang::OMPLoopBasedDirective::HelperExprs&) Expr.h:141
    #&#8203;1 0x11460fd76 in clang::Sema::ActOnOpenMPParallelForDirective(llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation, llvm::SmallDenseMap<clang::ValueDecl const*, clang::Expr const*, 4u, llvm::DenseMapInfo<clang::ValueDecl const*>, llvm::detail::DenseMapPair<clang::ValueDecl const*, clang::Expr const*> >&) SemaOpenMP.cpp:9974
    #&#8203;2 0x1145e4af5 in clang::Sema::ActOnOpenMPExecutableDirective(llvm::omp::Directive, clang::DeclarationNameInfo const&, llvm::omp::Directive, llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation) SemaOpenMP.cpp:5881
    #&#8203;3 0x112dae331 in clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext) ParseOpenMP.cpp:2562
    #&#8203;4 0x112e32b4a in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributesWithRange&) ParseStmt.cpp:405
    #&#8203;5 0x112e2e4bf in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) ParseStmt.cpp:113
    #&#8203;6 0x112e576b0 in clang::Parser::ParseCompoundStatementBody(bool) ParseStmt.cpp:1102
    #&#8203;7 0x112e5c5e8 in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) ParseStmt.cpp:2271
    #&#8203;8 0x112b4ff16 in clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) ParseCXXInlineMethods.cpp:581
    #&#8203;9 0x112b4a075 in clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) ParseCXXInlineMethods.cpp:513
    #&#8203;10 0x112c342be in clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributesWithRange&, unsigned int, clang::Decl*) ParseDeclCXX.cpp:3434
    #&#8203;11 0x112c25c5e in clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributesWithRange&) ParseDeclCXX.cpp:1990
    #&#8203;12 0x112b8c037 in clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) ParseDecl.cpp:3960
    #&#8203;13 0x112ecd102 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) Parser.cpp:1040
    #&#8203;14 0x112ecc505 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) Parser.cpp:1150
    #&#8203;15 0x112ec6a3b in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) Parser.cpp:970
    #&#8203;16 0x112ebeb85 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) Parser.cpp:716
    #&#8203;17 0x112b3823d in clang::ParseAST(clang::Sema&, bool, bool) ParseAST.cpp:158
    #&#8203;18 0x1125f8333 in clang::FrontendAction::Execute() FrontendAction.cpp:949
    #&#8203;19 0x11240e094 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) CompilerInstance.cpp:960
    #&#8203;20 0x1102a141a in clang::tooling::FrontendActionFactory::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) Tooling.cpp:400
    #&#8203;21 0x1102d6706 in clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) ClangTidy.cpp:566
    #&#8203;22 0x1102a0dc6 in clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::__1::shared_ptr<clang::CompilerInvocation>, std::__1::shared_ptr<clang::PCHContainerOperations>) Tooling.cpp:375
    #&#8203;23 0x11029d681 in clang::tooling::ToolInvocation::run() Tooling.cpp:360
    #&#8203;24 0x1102a5ba8 in clang::tooling::ClangTool::run(clang::tooling::ToolAction*) Tooling.cpp:554
    #&#8203;25 0x1102c88da in clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) ClangTidy.cpp:587
    #&#8203;26 0x11036029e in clang::tidy::clangTidyMain(int, char const**) ClangTidyMain.cpp:494
    #&#8203;27 0x7fff64aa43d4 in start (libdyld.dylib:x86_64+0x163d4)

==94711==Register values:
rax = 0x0000000000000000  rbx = 0x00007ffee1718580  rcx = 0x00001fffdc2e3042  rdx = 0x00000000ffffffef  
rdi = 0x0000000000000000  rsi = 0x000000010f6a93a4  rbp = 0x00007ffee1718820  rsp = 0x00007ffee1717e00  
 r8 = 0x00000001252f8b32   r9 = 0x0000000000000000  r10 = 0x0000000000000001  r11 = 0x00001fffdc2e3159  
r12 = 0x0000000000000000  r13 = 0x0000100000000000  r14 = 0x0000100000000001  r15 = 0x0000000000000008  
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV Expr.h:141 in checkOpenMPLoop(llvm::omp::Directive, clang::Expr*, clang::Expr*, clang::Stmt*, clang::Sema&, (anonymous namespace)::DSAStackTy&, llvm::SmallDenseMap<clang::ValueDecl const*, clang::Expr const*, 4u, llvm::DenseMapInfo<clang::ValueDecl const*>, llvm::detail::DenseMapPair<clang::ValueDecl const*, clang::Expr const*> >&, clang::OMPLoopBasedDirective::HelperExprs&)
==94711==ABORTING
zsh: abort      ~/Downloads/llvm-project/build/bin/clang-tidy -fix  --extra-arg=-v

This trace is on a build from source (6533451), but a similar crash occurs in 11.0 and 12.0. In this identical configuration, I can successfully parse the file if I comment out the #pragma omp statements. Clangd doesn't seem to have an issue with the same compile_commands.json, nor is there a problem actually compiling the file.

I don't know how, but I suspect the crash is related to the length of the command line args in some way. The reported invocation (passing --extra-arg=-v) is ~17000 characters, here it is without includes:

"clang" "-cc1" "-triple" "x86_64-apple-macosx10.14.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "file.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all" "-fno-rounding-math" "-munwind-tables" "-target-sdk-version=10.15" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "penryn" "-tune-cpu" "generic" "-debug-info-kind=standalone" "-dwarf-version=4" "-debugger-tuning=lldb" "-target-linker-version" "530" "-v" "-fcoverage-compilation-dir=/private/var/tmp/_bazel_jlaxson/e9aa1c1c50a034a5b219c928ee694ef9/execroot/theia" "-resource-dir" "/Users/jlaxson/Downloads/llvm-project/build/lib/clang/13.0.0" "-isysroot" "/Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk" "-D" "_FORTIFY_SOURCE=1" "-D" "NDEBUG" "-D" "NS_BLOCK_ASSERTIONS=1" "-F/Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks" "-F/Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks" "-D" "DATE=redacted" "-D" "TIMESTAMP=redacted" "-D" "TIME=redacted" "-D" "CERES_NO_SUITESPARSE" "-D" "CERES_NO_CXSPARSE" "-D" "CERES_NO_LAPACK" "-D" "CERES_USE_EIGEN_SPARSE" "-D" "CERES_GFLAGS_NAMESPACE=gflags" "-D" "CERES_USE_OPENMP" "-D" "BOOST_ASIO_SEPARATE_COMPILATION" "-D" "BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW" "-D" "_USE_BOOST" "-D" "_USE_OPENCV" "-D" "_USE_NONFREE" "-D" "_USE_FAST_FLOAT2INT" "-D" "_USE_FAST_CBRT" "-D" "_USE_OPENMP" "-D" "_USE_EIGEN" "-D" "_USE_SSE" "-D" "HAVE_CPUID_H" "-D" "XXH_PRIVATE_API" "-D" "HAVE_CONFIG_H" "-D" "LZMA_API_STATIC" "-stdlib=libc++" "-internal-isystem" "/Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/local/include" "-internal-isystem" "/Users/jlaxson/Downloads/llvm-project/build/lib/clang/13.0.0/include" "-internal-externc-isystem" "/Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include" "-O2" "-Wall" "-Wthread-safety" "-Wself-assign" "-Wno-builtin-macro-redefined" "-std=c++14" "-fdeprecated-macro" "-fdebug-compilation-dir=/private/var/tmp/_bazel_jlaxson/e9aa1c1c50a034a5b219c928ee694ef9/execroot/theia" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-fopenmp" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "file.cpp"

An invocation that passes (previous was generated by bazel, this one cmake), raw it is ~11000 characters, again without include flags

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" "-cc1" "-triple" "x86_64-apple-macosx10.14.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "file.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all" "-fno-rounding-math" "-munwind-tables" "-target-sdk-version=10.15" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "skylake" "-target-feature" "+sse2" "-target-feature" "+sse3" "-target-feature" "+ssse3" "-target-feature" "+sse4.1" "-target-feature" "+sse4.2" "-target-feature" "+avx" "-target-feature" "+fma" "-target-feature" "+bmi2" "-target-feature" "+avx2" "-target-feature" "-sse4a" "-target-feature" "-xop" "-target-feature" "-fma4" "-target-feature" "-avx512f" "-target-feature" "-avx512vl" "-target-feature" "-avx512pf" "-target-feature" "-avx512er" "-target-feature" "-avx512cd" "-target-feature" "-avx512dq" "-target-feature" "-avx512bw" "-target-feature" "-avx512ifma" "-target-feature" "-avx512vbmi" "-debug-info-kind=standalone" "-dwarf-version=4" "-debugger-tuning=lldb" "-target-linker-version" "530" "-v" "-fcoverage-compilation-dir=/Users/jlaxson/Documents/theia/build" "-resource-dir" "/Users/jlaxson/Downloads/llvm-project/build/lib/clang/13.0.0" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk" "-D" "BOOST_ALL_NO_LIB=1" "-D" "BOOST_SYSTEM_NO_DEPRECATED" "-D" "BOOST_THREAD_PROVIDES_EXECUTORS" "-D" "BOOST_THREAD_USES_CHRONO" "-D" "BOOST_THREAD_VERSION=4" "-D" "CGAL_HEADER_ONLY=1" "-D" "CGAL_USE_CORE=1" "-D" "GFLAGS_DLL_DECLARE_FLAG=" "-D" "GFLAGS_DLL_DEFINE_FLAG=" "-D" "GFLAGS_IS_A_DLL=0" "-D" "GOOGLE_GLOG_DLL_DECL=" "-D" "OPENMVG_STD_UNORDERED_MAP" "-D" "OPENMVG_USE_OPENMP" "-D" "NDEBUG" "-stdlib=libc++" "-internal-isystem" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1" "-internal-isystem" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/local/include" "-internal-isystem" "/Users/jlaxson/Downloads/llvm-project/build/lib/clang/13.0.0/include" "-internal-externc-isystem" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include" "-O2" "-Wall" "-Wsign-compare" "-Werror" "-Wrange-loop-analysis" "-Wno-pedantic" "-Wno-deprecated-declarations" "-Wno-uninitialized" "-Wno-narrowing" "-Wno-ignored-attributes" "-Wno-enum-compare" "-Wno-unused-function" "-std=gnu++14" "-fdeprecated-macro" "-fdebug-compilation-dir=/Users/jlaxson/Documents/theia/build" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-fopenmp" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "file.cpp"

Anecdotally we have noticed that stripping [irrelevant, like architecture flags a la -msse] flags from the compile_commands command line can cause clang-tidy to start working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang-tidycrashPrefer [crash-on-valid] or [crash-on-invalid]incompleteIssue not complete (e.g. missing a reproducer, build arguments, etc.)platform:macos

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions