<html>
    <head>
      <base href="http://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Null pointer crash caused by dyn_cast InheritanceGraphViewer"
   href="http://bugs.llvm.org/show_bug.cgi?id=32095">32095</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Null pointer crash caused by dyn_cast InheritanceGraphViewer
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arphaman@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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'</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>