Ericsson / clang

Cross Translation Unit analysis capability for Clang Static Analyzer. (Fork of official clang at http://llvm.org/git/clang)
http://clang.llvm.org/
Other
15 stars 10 forks source link

Assertion `MD->isVirtual() && "Method is not virtual!"' failed. #701

Closed balazske closed 4 years ago

balazske commented 5 years ago

Assertion during analysis of bitcoin with clang master commit 3c10f346dcd and applied patch in D65577 and D65935 and D65999.

clang/lib/AST/DeclCXX.cpp:2229: void clang::CXXMethodDecl::addOverriddenMethod(const clang::CXXMethodDecl*): Assertion `MD->isVirtual() && "Method is not virtual!"' failed.

  #0 0x00007f9c81b5dfda llvm::sys::PrintStackTrace(llvm::raw_ostream&) (lib/libLLVMSupport.so.10svn+0x191fda)
  #1 0x00007f9c81b5bcb4 llvm::sys::RunSignalHandlers() (lib/libLLVMSupport.so.10svn+0x18fcb4)
  #2 0x00007f9c81b5bdf2 SignalHandler(int) (lib/libLLVMSupport.so.10svn+0x18fdf2)
  #3 0x00007f9c7ecfff20 (/lib/x86_64-linux-gnu/libc.so.6+0x3ef20)
  #4 0x00007f9c7ecffe97 raise /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
  #5 0x00007f9c7ed01801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
  #6 0x00007f9c7ecf139a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
  #7 0x00007f9c7ecf1412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
  #8 0x00007f9c7ae6e9a5 clang::CXXMethodDecl::addOverriddenMethod(clang::CXXMethodDecl const*) (lib/libclangAST.so.10svn+0x2859a5)
  #9 0x00007f9c7add7562 clang::ASTNodeImporter::ImportOverrides(clang::CXXMethodDecl*, clang::CXXMethodDecl*) (lib/libclangAST.so.10svn+0x1ee562)
 #10 0x00007f9c7ad8dc3f clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) (lib/libclangAST.so.10svn+0x1a4c3f)
 #11 0x00007f9c7ad8e49d clang::ASTNodeImporter::VisitCXXMethodDecl(clang::CXXMethodDecl*) (lib/libclangAST.so.10svn+0x1a549d)
 #12 0x00007f9c7ad8e785 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5785)
 #13 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #14 0x00007f9c7ad90495 llvm::Expected<clang::Decl*> clang::ASTNodeImporter::import<clang::Decl>(clang::Decl*) (lib/libclangAST.so.10svn+0x1a7495)
 #15 0x00007f9c7adb982f clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) (lib/libclangAST.so.10svn+0x1d082f)
 #16 0x00007f9c7adb90c7 clang::ASTNodeImporter::ImportDefinition(clang::RecordDecl*, clang::RecordDecl*, clang::ASTNodeImporter::ImportDefinitionKind) (lib/libclangAST.so.10svn+0x1d00c7)
 #17 0x00007f9c7adc3cf1 clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*) (lib/libclangAST.so.10svn+0x1dacf1)
 #18 0x00007f9c7ad8e645 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5645)
 #19 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #20 0x00007f9c7ad91837 clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*) (lib/libclangAST.so.10svn+0x1a8837)
 #21 0x00007f9c7ad9fee5 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6ee5)
 #22 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #23 0x00007f9c7ada34d2 clang::ASTNodeImporter::VisitPointerType(clang::PointerType const*) (lib/libclangAST.so.10svn+0x1ba4d2)
 #24 0x00007f9c7ad9fe05 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6e05)
 #25 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #26 0x00007f9c7adae519 clang::ASTNodeImporter::VisitFunctionProtoType(clang::FunctionProtoType const*) (lib/libclangAST.so.10svn+0x1c5519)
 #27 0x00007f9c7ad9ffa5 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6fa5)
 #28 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #29 0x00007f9c7ada3ed8 llvm::Expected<std::tuple<clang::QualType> > clang::ASTNodeImporter::importSeq<clang::QualType>(clang::QualType const&) (lib/libclangAST.so.10svn+0x1baed8)
 #30 0x00007f9c7ad8cc07 clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) (lib/libclangAST.so.10svn+0x1a3c07)
 #31 0x00007f9c7ad8e49d clang::ASTNodeImporter::VisitCXXMethodDecl(clang::CXXMethodDecl*) (lib/libclangAST.so.10svn+0x1a549d)
 #32 0x00007f9c7ad8e785 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5785)
 #33 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #34 0x00007f9c7ad90495 llvm::Expected<clang::Decl*> clang::ASTNodeImporter::import<clang::Decl>(clang::Decl*) (lib/libclangAST.so.10svn+0x1a7495)
 #35 0x00007f9c7adb982f clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) (lib/libclangAST.so.10svn+0x1d082f)
 #36 0x00007f9c7adb90c7 clang::ASTNodeImporter::ImportDefinition(clang::RecordDecl*, clang::RecordDecl*, clang::ASTNodeImporter::ImportDefinitionKind) (lib/libclangAST.so.10svn+0x1d00c7)
 #37 0x00007f9c7adc3cf1 clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*) (lib/libclangAST.so.10svn+0x1dacf1)
 #38 0x00007f9c7ad8e645 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5645)
 #39 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #40 0x00007f9c7ad91837 clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*) (lib/libclangAST.so.10svn+0x1a8837)
 #41 0x00007f9c7ad9fee5 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6ee5)
 #42 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #43 0x00007f9c7ada34d2 clang::ASTNodeImporter::VisitPointerType(clang::PointerType const*) (lib/libclangAST.so.10svn+0x1ba4d2)
 #44 0x00007f9c7ad9fe05 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6e05)
 #45 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #46 0x00007f9c7adae485 clang::ASTNodeImporter::VisitFunctionProtoType(clang::FunctionProtoType const*) (lib/libclangAST.so.10svn+0x1c5485)
 #47 0x00007f9c7ad9ffa5 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6fa5)
 #48 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #49 0x00007f9c7ada3ed8 llvm::Expected<std::tuple<clang::QualType> > clang::ASTNodeImporter::importSeq<clang::QualType>(clang::QualType const&) (lib/libclangAST.so.10svn+0x1baed8)
 #50 0x00007f9c7ad8cc07 clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) (lib/libclangAST.so.10svn+0x1a3c07)
 #51 0x00007f9c7ad8e49d clang::ASTNodeImporter::VisitCXXMethodDecl(clang::CXXMethodDecl*) (lib/libclangAST.so.10svn+0x1a549d)
 #52 0x00007f9c7ad8e785 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5785)
 #53 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #54 0x00007f9c7ad90495 llvm::Expected<clang::Decl*> clang::ASTNodeImporter::import<clang::Decl>(clang::Decl*) (lib/libclangAST.so.10svn+0x1a7495)
 #55 0x00007f9c7adb982f clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) (lib/libclangAST.so.10svn+0x1d082f)
 #56 0x00007f9c7adb90c7 clang::ASTNodeImporter::ImportDefinition(clang::RecordDecl*, clang::RecordDecl*, clang::ASTNodeImporter::ImportDefinitionKind) (lib/libclangAST.so.10svn+0x1d00c7)
 #57 0x00007f9c7adc3cf1 clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*) (lib/libclangAST.so.10svn+0x1dacf1)
 #58 0x00007f9c7ad8e645 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5645)
 #59 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #60 0x00007f9c7ad91837 clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*) (lib/libclangAST.so.10svn+0x1a8837)
 #61 0x00007f9c7ad9fee5 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) (lib/libclangAST.so.10svn+0x1b6ee5)
 #62 0x00007f9c7ada00c1 clang::ASTImporter::Import(clang::QualType) (lib/libclangAST.so.10svn+0x1b70c1)
 #63 0x00007f9c7adb8d3c clang::ASTNodeImporter::ImportDefinition(clang::RecordDecl*, clang::RecordDecl*, clang::ASTNodeImporter::ImportDefinitionKind) (lib/libclangAST.so.10svn+0x1cfd3c)
 #64 0x00007f9c7adc3cf1 clang::ASTNodeImporter::VisitRecordDecl(clang::RecordDecl*) (lib/libclangAST.so.10svn+0x1dacf1)
 #65 0x00007f9c7ad8e645 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5645)
 #66 0x00007f9c7ad8ec7b clang::ASTImporter::Import(clang::Decl*) (lib/libclangAST.so.10svn+0x1a5c7b)
 #67 0x00007f9c7ad91837 clang::ASTNodeImporter::VisitRecordType(clang::RecordType const*) (lib/libclangAST.so.10svn+0x1a8837)
balazske commented 5 years ago

This problem happens because there are import errors during ASTNodeImporter::ImportOverrides. The source of the error (name conflict) must be investigated but in general it can be problem if we get error there:

struct A {
  virtual void f();
};
struct B : public A {
  void f() override;
};
struct C : public B {
  void f() override;
};

In this case the overridden method for C::f is B::f and CXXRecordDecl::isVirtual should be true for B::f when addOverriddenMethod is called. If import of A::f failed but not B::f and C::f the overridden method for B::f is not set so it is "not virtual" (isVirtual is false).

martong commented 5 years ago

Could we set the error for all overrides (B::f, C::f) in case we have an error in the overridden (A::f)?

balazske commented 5 years ago

It looks like that #564 (https://reviews.llvm.org/D62131) makes the NameConflict errors (and the assertion) disappear. Still the ImportOverrides can be made to return Error.

martong commented 5 years ago

FYI, https://reviews.llvm.org/D62131 is not merged to master yet. So, perhaps there is something else