LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47778 - Crash with macro and recently introduced cppcoreguidelines-prefer-member-initializer
Summary: Crash with macro and recently introduced cppcoreguidelines-prefer-member-init...
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Ádám Balogh
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2020-10-09 05:00 PDT by Volker Reichelt
Modified: 2021-02-22 12:10 PST (History)
6 users (show)

See Also:
Fixed By Commit(s): a2e15fa5


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2020-10-09 05:00:34 PDT
The following valid code snippet triggers an assertion with the command line
"clang-tidy -checks='-*,cppcoreguidelines-prefer-member-initializer' bug.cc --":

=================================================
#define FOO struct A { int i; A() { i = 0; } };
FOO
=================================================

clang-tidy: /llvm-project/llvm/include/llvm/ADT/Optional.h:173: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = clang::Token]: Assertion `hasVal' failed.

Stack dump:
0.	Program arguments: /llvm-trunk/bin/clang-tidy -checks=-*,cppcoreguidelines-prefer-member-initializer bug.cc -- 
1.	<eof> parser at end of file
 #0 0x00000000025e9c1c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/llvm-trunk/bin/clang-tidy+0x25e9c1c)
 #1 0x00000000025e7a94 llvm::sys::RunSignalHandlers() (/llvm-trunk/bin/clang-tidy+0x25e7a94)
 #2 0x00000000025e7be8 SignalHandler(int) (/llvm-trunk/bin/clang-tidy+0x25e7be8)
 #3 0x00007f090ebd9680 __restore_rt (/lib64/libpthread.so.0+0xf680)
 #4 0x00007f090d974207 raise (/lib64/libc.so.6+0x36207)
 #5 0x00007f090d9758f8 abort (/lib64/libc.so.6+0x378f8)
 #6 0x00007f090d96d026 __assert_fail_base (/lib64/libc.so.6+0x2f026)
 #7 0x00007f090d96d0d2 (/lib64/libc.so.6+0x2f0d2)
 #8 0x00000000005cf373 clang::tidy::cppcoreguidelines::PreferMemberInitializerCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-trunk/bin/clang-tidy+0x5cf373)
 #9 0x0000000001f3d8f8 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) (/llvm-trunk/bin/clang-tidy+0x1f3d8f8)
#10 0x0000000001f7e797 clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/llvm-trunk/bin/clang-tidy+0x1f7e797)
#11 0x0000000001f3f31a clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) (/llvm-trunk/bin/clang-tidy+0x1f3f31a)
#12 0x0000000001f5ee9d clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) (.part.6933) (/llvm-trunk/bin/clang-tidy+0x1f5ee9d)
#13 0x0000000001f6138a clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.6934) (/llvm-trunk/bin/clang-tidy+0x1f6138a)
#14 0x0000000001f77eda clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseCXXRecordDecl(clang::CXXRecordDecl*) (/llvm-trunk/bin/clang-tidy+0x1f77eda)
#15 0x0000000001f5fca3 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) (.part.6933) (/llvm-trunk/bin/clang-tidy+0x1f5fca3)
#16 0x0000000001f6138a clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.6934) (/llvm-trunk/bin/clang-tidy+0x1f6138a)
#17 0x0000000001f606bc clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) (.part.6933) (/llvm-trunk/bin/clang-tidy+0x1f606bc)
#18 0x0000000001f60f11 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/llvm-trunk/bin/clang-tidy+0x1f60f11)
#19 0x0000000001365d18 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/llvm-trunk/bin/clang-tidy+0x1365d18)
#20 0x00000000014ec219 clang::ParseAST(clang::Sema&, bool, bool) (/llvm-trunk/bin/clang-tidy+0x14ec219)
#21 0x0000000001349f89 clang::FrontendAction::Execute() (/llvm-trunk/bin/clang-tidy+0x1349f89)
#22 0x0000000001301cd2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/llvm-trunk/bin/clang-tidy+0x1301cd2)
#23 0x0000000000cd729e clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/llvm-trunk/bin/clang-tidy+0xcd729e)
#24 0x0000000000c8c7d9 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, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/llvm-trunk/bin/clang-tidy+0xc8c7d9)
#25 0x0000000000ccf334 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/llvm-trunk/bin/clang-tidy+0xccf334)
#26 0x0000000000cd3915 clang::tooling::ToolInvocation::run() (/llvm-trunk/bin/clang-tidy+0xcd3915)
#27 0x0000000000cd64b8 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/llvm-trunk/bin/clang-tidy+0xcd64b8)
#28 0x0000000000c92ac8 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, llvm::StringRef) (/llvm-trunk/bin/clang-tidy+0xc92ac8)
#29 0x00000000004580ce clang::tidy::clangTidyMain(int, char const**) (/llvm-trunk/bin/clang-tidy+0x4580ce)
Comment 1 Ádám Balogh 2020-10-14 03:28:49 PDT
Fix: https://reviews.llvm.org/D89380