Bug 358740 - Utils::isInitializedExternally: getSingleDecl fails to account for multiple declarations
Summary: Utils::isInitializedExternally: getSingleDecl fails to account for multiple d...
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-29 15:53 UTC by Jan Kundrát
Modified: 2016-01-30 15:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kundrát 2016-01-29 15:53:39 UTC
The following minimal example causes an assertion failure within clang in a code path triggered by the clazy plugin:

#include <QtCore/QList>
void x()
{
    QList<int> list;
    int a, b;
}

Here's the backtrace:

(gdb) bt
#0  0x00007fffec04989b in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007fffec04ae51 in __GI_abort () at abort.c:89
#2  0x00007fffec041fb8 in __assert_fail_base (fmt=0x7fffec18ace0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7fffe4b00fe0 "isSingleDecl() && \"Isn't a declgroup\"", 
    file=file@entry=0x7fffe4b01006 "/usr/include/clang/AST/DeclGroup.h", line=line@entry=88, function=function@entry=0x7fffe4b01029 "clang::Decl *clang::DeclGroupRef::getSingleDecl()") at assert.c:92
#3  0x00007fffec042076 in __GI___assert_fail (assertion=0x7fffe4b00fe0 "isSingleDecl() && \"Isn't a declgroup\"", file=0x7fffe4b01006 "/usr/include/clang/AST/DeclGroup.h", line=88, 
    function=0x7fffe4b01029 "clang::Decl *clang::DeclGroupRef::getSingleDecl()") at assert.c:101
#4  0x00007fffe4a02cea in clang::DeclGroupRef::getSingleDecl() () from /home/jkt/.local/lib64/ClangLazy.so
#5  0x00007fffe4a028c9 in clang::DeclStmt::getSingleDecl() () from /home/jkt/.local/lib64/ClangLazy.so
#6  0x00007fffe4acb339 in Utils::isInitializedExternally(clang::VarDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#7  0x00007fffe4a0877e in InefficientQListBase::shouldIgnoreVariable(clang::VarDecl*) const () from /home/jkt/.local/lib64/ClangLazy.so
#8  0x00007fffe4a08828 in InefficientQListBase::VisitDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#9  0x00007fffe49dbe26 in CheckBase::VisitDeclaration(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#10 0x00007fffe4a45323 in (anonymous namespace)::LazyASTConsumer::VisitDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#11 0x00007fffe4a45285 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::WalkUpFromDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#12 0x00007fffe4a7ba45 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::WalkUpFromNamedDecl(clang::NamedDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#13 0x00007fffe4a7dfa5 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::WalkUpFromValueDecl(clang::ValueDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#14 0x00007fffe4a7def5 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::WalkUpFromDeclaratorDecl(clang::DeclaratorDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#15 0x00007fffe4a7eba5 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::WalkUpFromVarDecl(clang::VarDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#16 0x00007fffe4a4223d in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseVarDecl(clang::VarDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#17 0x00007fffe4a3ecf5 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#18 0x00007fffe4a56654 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseDeclStmt(clang::DeclStmt*) () from /home/jkt/.local/lib64/ClangLazy.so
#19 0x00007fffe4a46c41 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseStmt(clang::Stmt*) () from /home/jkt/.local/lib64/ClangLazy.so
#20 0x00007fffe4a5641f in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseCompoundStmt(clang::CompoundStmt*) () from /home/jkt/.local/lib64/ClangLazy.so
#21 0x00007fffe4a46be7 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseStmt(clang::Stmt*) () from /home/jkt/.local/lib64/ClangLazy.so
#22 0x00007fffe4a7e5f0 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseFunctionHelper(clang::FunctionDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#23 0x00007fffe4a41e20 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseFunctionDecl(clang::FunctionDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#24 0x00007fffe4a3eb66 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#25 0x00007fffe4a45215 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseDeclContextHelper(clang::DeclContext*) () from /home/jkt/.local/lib64/ClangLazy.so
#26 0x00007fffe4a42e6a in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) () from /home/jkt/.local/lib64/ClangLazy.so
#27 0x00007fffe4a3ef68 in clang::RecursiveASTVisitor<(anonymous namespace)::LazyASTConsumer>::TraverseDecl(clang::Decl*) () from /home/jkt/.local/lib64/ClangLazy.so
#28 0x00007fffe4a3e05d in (anonymous namespace)::LazyASTConsumer::HandleTranslationUnit(clang::ASTContext&) () from /home/jkt/.local/lib64/ClangLazy.so
#29 0x00007fffecbe61e0 in clang::MultiplexConsumer::HandleTranslationUnit (this=<optimized out>, Ctx=...)
    at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/Frontend/MultiplexConsumer.cpp:296
#30 0x00007fffe70161ad in clang::ParseAST (S=..., PrintStats=<optimized out>, SkipFunctionBodies=<optimized out>)
    at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/Parse/ParseAST.cpp:151
#31 0x00007fffecbbc71a in clang::ASTFrontendAction::ExecuteAction (this=this@entry=0x5555557918e0)
    at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/Frontend/FrontendAction.cpp:537
#32 0x00007fffed35bded in clang::CodeGenAction::ExecuteAction (this=0x5555557918e0) at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/CodeGen/CodeGenAction.cpp:744
#33 0x00007fffecbbdb6e in clang::FrontendAction::Execute (this=this@entry=0x5555557918e0) at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/Frontend/FrontendAction.cpp:439
#34 0x00007fffecb8b109 in clang::CompilerInstance::ExecuteAction (this=this@entry=0x555555783610, Act=...)
    at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/Frontend/CompilerInstance.cpp:820
#35 0x00007fffec907a91 in clang::ExecuteCompilerInvocation (Clang=Clang@entry=0x555555783610)
    at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:222
#36 0x000055555556638f in cc1_main (Argv=..., Argv0=<optimized out>, MainAddr=<optimized out>) at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/tools/driver/cc1_main.cpp:116
#37 0x0000555555561755 in ExecuteCC1Tool (Tool=..., argv=...) at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/tools/driver/driver.cpp:358
#38 main (argc_=<optimized out>, argv_=<optimized out>) at /var/tmp/portage/sys-devel/llvm-3.7.0-r2/work/llvm-3.7.0.src/tools/clang/tools/driver/driver.cpp:404

Please note that there's also another call to the getSingleDecl somewhere else in clazy's codebase.

Reproducible: Always
Comment 1 Sergio Martins 2016-01-30 15:32:56 UTC
Git commit 66b4e64dff863ce67195e82f081b3a6afd786e27 by Sergio Martins.
Committed on 30/01/2016 at 15:32.
Pushed by smartins into branch 'master'.

inefficient-qlist: Add test-case for a bug report

M  +5    -1    tests/inefficient-qlist/main.cpp

http://commits.kde.org/clazy/66b4e64dff863ce67195e82f081b3a6afd786e27
Comment 2 Sergio Martins 2016-01-30 15:36:00 UTC
Git commit f6008a4bf95a4799673327f4333dd3069935b7a0 by Sergio Martins.
Committed on 30/01/2016 at 15:35.
Pushed by smartins into branch 'master'.

inefficient-qlist-soft: Also add test-case here

M  +6    -0    tests/inefficient-qlist-soft/main.cpp

http://commits.kde.org/clazy/f6008a4bf95a4799673327f4333dd3069935b7a0
Comment 3 Sergio Martins 2016-01-30 15:57:49 UTC
Git commit 31b2e1b2ff8b67c95fb476390d1f6211e98daff6 by Sergio Martins.
Committed on 30/01/2016 at 15:56.
Pushed by smartins into branch 'master'.

inefficient-qlist-soft: Fix crash with older clang

Calling DeclStmt::getSingleDecl() will crash if the DeclStmt
doesn't have a single decl.

M  +14   -1    Utils.cpp
M  +5    -0    Utils.h

http://commits.kde.org/clazy/31b2e1b2ff8b67c95fb476390d1f6211e98daff6