Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 710766

Summary: sys-devel/clang:9 crashes on parsing C++
Product: Gentoo Linux Reporter: Vasiliy Yeremeyev <vayerx>
Component: Current packagesAssignee: LLVM support project <llvm>
Status: RESOLVED FIXED    
Severity: normal CC: jstein, mgorny
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: All   
OS: Linux   
See Also: https://bugs.llvm.org/show_bug.cgi?id=34960
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: emerge --info
Hotfix

Description Vasiliy Yeremeyev 2020-02-25 09:34:29 UTC
Created attachment 615676 [details]
emerge --info

I'm using KDevelop which uses clang to process C++. Clang repeatedly crashes on parsing of large C++ project (couldn't find out exact place). Clang runs in the kdevelop process so IDE becomes totaly unusable -- it can't analyze the whole project and restarts.

sys-devel/clang-9.0.1
sys-devel/llvm-9.0.1
dev-util/kdevelop-5.5.0

#0  clang::Decl::setInvalidDecl(bool) (this=0x0, Invalid=true) at clang/lib/AST/DeclBase.cpp:132
#1  0x00007fffb92cdf9c in clang::Decl::setInvalidDecl(bool) (this=this@entry=0x7fff76c86940, Invalid=<optimized out>)
    at clang/lib/AST/DeclBase.cpp:149
#2  0x00007fffba010bb4 in clang::ASTDeclReader::VisitDecl(clang::Decl*) (this=0x7fff927f78c0, D=0x7fff76c86940)
    at /usr/lib/llvm/9/include/llvm/ADT/SmallVector.h:148
#3  0x00007fffba011a41 in clang::ASTDeclReader::VisitNamedDecl(clang::NamedDecl*) (this=this@entry=0x7fff927f78c0, ND=ND@entry=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:657
#4  0x00007fffba011c01 in clang::ASTDeclReader::VisitValueDecl(clang::ValueDecl*) (this=0x7fff927f78c0, VD=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:806
#5  0x00007fffba011c99 in clang::ASTDeclReader::VisitDeclaratorDecl(clang::DeclaratorDecl*) (this=this@entry=0x7fff927f78c0, DD=DD@entry=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:825
#6  0x00007fffba03161c in clang::ASTDeclReader::VisitVarDeclImpl(clang::VarDecl*) (this=this@entry=0x7fff927f78c0, VD=VD@entry=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:1362
#7  0x00007fffba032153 in clang::ASTDeclReader::VisitVarDecl(clang::VarDecl*) (VD=0x7fff76c86940, this=0x7fff927f78c0)
    at clang/lib/Serialization/ASTReaderDecl.cpp:378
#8  clang::ASTDeclReader::VisitDecompositionDecl(clang::DecompositionDecl*) (this=0x7fff927f78c0, DD=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:1464
#9  0x00007fffba034c42 in clang::ASTDeclReader::Visit(clang::Decl*) (this=0x7fff927f78c0, D=0x7fff76c86940)
    at clang/lib/Serialization/ASTReaderDecl.cpp:522
#10 0x00007fffba03570f in clang::ASTReader::ReadDeclRecord(unsigned int) (this=0x7fff3d8d9f10, ID=ID@entry=208781)
    at clang/lib/Serialization/ASTReaderDecl.cpp:3967
#11 0x00007fffb9f85df9 in clang::ASTReader::GetDecl(unsigned int) (ID=208781, this=0x7fff3d8d9f10)
    at clang/lib/Serialization/ASTReader.cpp:7800
#12 clang::ASTReader::GetDecl(unsigned int) (this=0x7fff3d8d9f10, ID=208781)
    at clang/lib/Serialization/ASTReader.cpp:7787
#13 0x00007fffba037811 in clang::ASTReader::ReadDecl(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long, 64u> const&, unsigned int&)
    (I=<optimized out>, R=..., F=..., this=0x7fff3d8d9f10) at clang/include/clang/Serialization/ASTReader.h:1870
#14 clang::ASTRecordReader::readDecl() (this=<optimized out>) at clang/include/clang/Serialization/ASTReader.h:2524
#15 clang::ASTStmtReader::ReadDecl() (this=0x7fff927f7d70) at clang/lib/Serialization/ASTReaderStmt.cpp:91
#16 clang::ASTStmtReader::VisitDeclStmt(clang::DeclStmt*) (this=0x7fff927f7d70, S=0x7fff76c86920)
    at clang/lib/Serialization/ASTReaderStmt.cpp:348
#17 0x00007fffba04a47c in clang::ASTReader::ReadStmtFromStream(clang::serialization::ModuleFile&) (this=this@entry=0x7fff3d8d9f10, F=...)
    at clang/lib/Serialization/ASTReaderStmt.cpp:3464
#18 0x00007fffb9fa8db2 in clang::ASTReader::GetExternalDeclStmt(unsigned long) (this=0x7fff3d8d9f10, Offset=<optimized out>)
    at clang/lib/Serialization/ASTReader.cpp:7854
#19 0x00007fffb92c4df3 in clang::LazyOffsetPtr<clang::Stmt, unsigned long, &clang::ExternalASTSource::GetExternalDeclStmt>::get(clang::ExternalASTSource*) const (Source=<optimized out>, this=0x7fff76c84358) at clang/include/clang/AST/ExternalASTSource.h:400
#20 clang::FunctionDecl::getBody(clang::FunctionDecl const*&) const (this=this@entry=0x7fff76c842d8, Definition=@0x7fff927f8148: 0x7fff76c842d8)


(gdb) l DeclBase.cpp:149
145	  // Marking a DecompositionDecl as invalid implies all the child BindingDecl's
146	  // are invalid too.
147	  if (auto *DD = dyn_cast<DecompositionDecl>(this)) {
148	    for (auto *Binding : DD->bindings()) {
149	      Binding->setInvalidDecl();
150	    }
151	  }

Trivial hotfix helps (but the real reason of the bug may be elsewhere):
--- a/lib/AST/DeclBase.cpp	2019-12-11 22:15:30.000000000 +0300
+++ b/lib/AST/DeclBase.cpp	2020-02-21 22:15:30.000000000 +0300
@@ -146,7 +146,9 @@
   // are invalid too.
   if (auto *DD = dyn_cast<DecompositionDecl>(this)) {
     for (auto *Binding : DD->bindings()) {
-      Binding->setInvalidDecl();
+      if (Binding) {
+        Binding->setInvalidDecl();
+      }
     }
   }
 }

Corresponding bug: https://bugs.llvm.org/show_bug.cgi?id=34960
Comment 1 Vasiliy Yeremeyev 2020-02-25 10:07:31 UTC
Created attachment 615678 [details, diff]
Hotfix
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-03-01 19:03:39 UTC
I'm sorry but I don't accept patches like this unless they're merged upstream.  I know it's a mess but my suggestion right now would be to try 11.0.0.9999 (presuming kdevelop supports it).  If it still happens, the patch needs to be submitted upstream -- but I don't think it's going to be accepted unless someone manages to make a good reproducer for it.