[cfe-dev] clang-tidy: readability-redundant-declaration assertion failure

Daniel Marjamäki via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 21 05:43:37 PST 2016


Hello!

Thanks for reporting this bug.

> I've tried a trivial workaround in RedundantDeclarationCheck::check(), to call
> diag() only in case 'Prev->getLocation().isInvalid()' is true, but that did not
> help, nor feels like a proper fix.

I think it sounds reasonable to bailout not valid. I only intended to warn when there are duplicate declarations in the code.

For me that bailout fixed the crash.

http://reviews.llvm.org/D26911

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden

Mobile:                 +46 (0)709 12 42 62
E-mail:                 Daniel.Marjamaki at evidente.se

www.evidente.se

________________________________________
From: Miklos Vajna [vmiklos at vmiklos.hu]
Sent: 20 November 2016 21:26
To: cfe-dev at lists.llvm.org
Cc: Daniel Marjamäki; Alexander Kornienko
Subject: clang-tidy: readability-redundant-declaration assertion failure

Hi,

The readability-redundant-declaration check hits an assertion failure
when including a number of system headers, e.g. tuple. Here is a
stripped down test.cpp:

----
namespace std {
typedef long unsigned int size_t;
}

void* operator new(std::size_t) __attribute__((__externally_visible__));
void* operator new[](std::size_t) __attribute__((__externally_visible__));
----

Then running 'clang-tidy -checks=-*,readability-redundant-declaration
test.cpp --' results in:

----
clang-tidy: /git/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:183: clang::DiagnosticBuilder clang::tidy::ClangTidyContext::diag(llvm::StringRef, clang::SourceLocation, llvm::StringRef, clang::DiagnosticIDs::Level): Assertion `Loc.isValid()' failed.
Aborted
----

Here is the backtrace:

----
#0  0x00007ffff3f0d0c7 in raise () from /lib64/libc.so.6
#1  0x00007ffff3f0e478 in abort () from /lib64/libc.so.6
#2  0x00007ffff3f06146 in __assert_fail_base () from /lib64/libc.so.6
#3  0x00007ffff3f061f2 in __assert_fail () from /lib64/libc.so.6
#4  0x00007ffff68ade63 in clang::tidy::ClangTidyContext::diag (this=<optimized out>, CheckName=..., Loc=..., Description=..., Level=Level at entry=clang::DiagnosticIDs::Note) at /git/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:183
#5  0x00007ffff689534e in clang::tidy::ClangTidyCheck::diag (this=this at entry=0x689310, Loc=..., Message=..., Level=Level at entry=clang::DiagnosticIDs::Note) at /git/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp:405
#6  0x00007ffff4e12601 in clang::tidy::readability::RedundantDeclarationCheck::check (this=0x689310, Result=...) at /git/llvm/tools/clang/tools/extra/clang-tidy/readability/RedundantDeclarationCheck.cpp:66
#7  0x00007ffff6fbf2bc in clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch (this=0x7fffffffb5f0, BoundNodesView=...) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:723
#8  0x00007ffff6fe258f in clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches (this=this at entry=0x7fffffffb630, ResultVisitor=ResultVisitor at entry=0x7fffffffb5f0) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchersInternal.cpp:48
#9  0x00007ffff6fc4fcb in clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter (this=this at entry=0x7fffffffbc60, DynNode=...) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:569
#10 0x00007ffff6fd7ba8 in clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchDispatch (Node=0xa004f8, this=0x7fffffffbc60) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:590
#11 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::match<clang::Decl> (Node=..., this=0x7fffffffbc60) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:494
#12 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl (this=this at entry=0x7fffffffbc60, DeclNode=DeclNode at entry=0xa004f8) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:837
#13 0x00007ffff6fd81b4 in clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper (this=this at entry=0x7fffffffbc60, DC=<optimized out>) at /git/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1318
#14 0x00007ffff6fd822e in clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseLinkageSpecDecl (this=this at entry=0x7fffffffbc60, D=<optimized out>) at /git/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1398
#15 0x00007ffff6fd6975 in clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl (this=this at entry=0x7fffffffbc60, D=D at entry=0x9f9af8) at /git/llvm/workdir/tools/clang/include/clang/AST/DeclNodes.inc:89
#16 0x00007ffff6fd7bb3 in clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl (this=this at entry=0x7fffffffbc60, DeclNode=DeclNode at entry=0x9f9af8) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:838
#17 0x00007ffff6fd81b4 in clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper (this=this at entry=0x7fffffffbc60, DC=<optimized out>) at /git/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1318
#18 0x00007ffff6fd68eb in clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl (D=<optimized out>, this=<optimized out>) at /git/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1410
#19 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl (this=this at entry=0x7fffffffbc60, D=D at entry=0x681f50) at /git/llvm/workdir/tools/clang/include/clang/AST/DeclNodes.inc:541
#20 0x00007ffff6fd7bb3 in clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl (this=this at entry=0x7fffffffbc60, DeclNode=0x681f50) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:838
#21 0x00007ffff6fd7e08 in clang::ast_matchers::MatchFinder::matchAST (this=<optimized out>, Context=...) at /git/llvm/tools/clang/lib/ASTMatchers/ASTMatchFinder.cpp:1014
#22 0x00007ffff24a4048 in clang::MultiplexConsumer::HandleTranslationUnit (this=<optimized out>, Ctx=...) at /git/llvm/tools/clang/lib/Frontend/MultiplexConsumer.cpp:305
#23 0x00007fffefaca932 in clang::ParseAST (S=..., PrintStats=<optimized out>, SkipFunctionBodies=<optimized out>) at /git/llvm/tools/clang/lib/Parse/ParseAST.cpp:159
#24 0x00007ffff24840d6 in clang::FrontendAction::Execute (this=this at entry=0x66dbd0) at /git/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458
#25 0x00007ffff2454966 in clang::CompilerInstance::ExecuteAction (this=this at entry=0x7fffffffbf10, Act=warning: RTTI symbol not found for class 'clang::tidy::runClangTidy(std::unique_ptr<clang::tidy::ClangTidyOptionsProvider, std::default_delete<clang::tidy::ClangTidyOptionsProvider> >, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::string>, std::vector<clang::tidy::ClangTidyError, std::allocator<clang::tidy::ClangTidyError> >*, clang::tidy::ProfileData*)::ActionFactory::Action'
...) at /git/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:885
#26 0x00007ffff4b6133f in clang::tooling::FrontendActionFactory::runInvocation (this=<optimized out>, Invocation=0x666510, Files=0x654cb0, PCHContainerOps=..., DiagConsumer=<optimized out>) at /git/llvm/tools/clang/lib/Tooling/Tooling.cpp:318
#27 0x00007ffff4b5bfb7 in clang::tooling::ToolInvocation::runInvocation (this=this at entry=0x7fffffffc9a0, BinaryName=BinaryName at entry=0x65adf8 "c++", Compilation=Compilation at entry=0x665420, Invocation=Invocation at entry=0x666510, PCHContainerOps=std::shared_ptr (empty) 0x0) at /git/llvm/tools/clang/lib/Tooling/Tooling.cpp:294
#28 0x00007ffff4b5e4dc in clang::tooling::ToolInvocation::run (this=this at entry=0x7fffffffc9a0) at /git/llvm/tools/clang/lib/Tooling/Tooling.cpp:279
#29 0x00007ffff4b5f958 in clang::tooling::ClangTool::run (this=this at entry=0x7fffffffcbd0, Action=Action at entry=0x7fffffffcb70) at /git/llvm/tools/clang/lib/Tooling/Tooling.cpp:454
#30 0x00007ffff68a57c3 in clang::tidy::runClangTidy (OptionsProvider=std::unique_ptr<clang::tidy::ClangTidyOptionsProvider> containing 0x0, Compilations=..., InputFiles=..., Errors=Errors at entry=0x7fffffffd490, Profile=0x0) at /git/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp:535
#31 0x000000000041d5a0 in clang::tidy::clangTidyMain (argc=14, argv=<optimized out>) at /git/llvm/tools/clang/tools/extra/clang-tidy/tool/ClangTidyMain.cpp:378
#32 0x00007ffff3ef9b25 in __libc_start_main () from /lib64/libc.so.6
#33 0x000000000040ceae in _start () at ../sysdeps/x86_64/start.S:122
----

This is with trunk llvm/clang/clang-tools-extra, i.e. clang-tools-extra r287330.

I've tried a trivial workaround in RedundantDeclarationCheck::check(), to call
diag() only in case 'Prev->getLocation().isInvalid()' is true, but that did not
help, nor feels like a proper fix.

Any ideas what can be the problem? :-)

Thanks,

Miklos



More information about the cfe-dev mailing list