http://bugs.llvm.org/show_bug.cgi?id=32095

            Bug ID: 32095
           Summary: Null pointer crash caused by dyn_cast
                    InheritanceGraphViewer
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Clang crashes when trying to generate inheritance graph for the record 'C' from
the following code:

  template <class T> struct A {};
  template <class U> class C: A<U>{};

Sample code from AST Visitor that reproduces this problem:

  bool Visitor::VisitCXXRecordDecl(clang::CXXRecordDecl *c) {
    if (c->getNumBases() || c->getNumVBases()) {
     c->viewInheritance(astContext);
    }
    return true;
  }


Backtrace:

  * frame #0: 0x000000010089f970
libclang.dylib`clang::TagType::getDecl(this=0x0000000000000000) const + 16 at
Type.cpp:3018
    frame #1: 0x00000001003dfbd5
libclang.dylib`clang::RecordType::getDecl(this=0x0000000000000000) const + 21
at Type.h:3760
    frame #2: 0x00000001007aba01 libclang.dylib`(anonymous
namespace)::InheritanceHierarchyWriter::WriteNode(this=0x00007fff5fbfd5b0,
Type=QualType @ 0x00007fff5fbfd130, FromVirtual=false) + 2641 at
InheritViz.cpp:95
    frame #3: 0x00000001007aaee2 libclang.dylib`(anonymous
namespace)::InheritanceHierarchyWriter::WriteGraph(this=0x00007fff5fbfd5b0,
Type=QualType @ 0x00007fff5fbfd538) + 146 at InheritViz.cpp:47
    frame #4: 0x00000001007aad64
libclang.dylib`clang::CXXRecordDecl::viewInheritance(this=0x0000000110809150,
Context=0x000000010f805600) const + 564 at InheritViz.cpp:153

The problem is caused by this dyn_cast from InheritViz.cpp:

  const CXXRecordDecl *Decl
    = static_cast<const CXXRecordDecl *>(Type->getAs<RecordType>()->getDecl());

The actual type is:

InjectedClassNameType 0x7f868380e7d0 'C<U>' dependent
`-CXXRecord 0x7f868380e550 'C'

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to