<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Crash by using ClangTool and --serialize-diagonstics-option"
   href="http://llvm.org/bugs/show_bug.cgi?id=22189">22189</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Crash by using ClangTool and --serialize-diagonstics-option
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>raise.rescue@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13663" name="attach_13663" title="Test-case for reproducing">attachment 13663</a> <a href="attachment.cgi?id=13663&action=edit" title="Test-case for reproducing">[details]</a></span>
Test-case for reproducing

I'm writing a ClangTool that uses auto-generated compilation-databases, so some
of them contain the --serialize-diagnostics-option. When the ClangTool tries to
build the AST, it crashes in the destructor of a BitStreamWriter.

I'm attaching a test-case that reproduces the crash and produces the following
output on my machine:

/a.cc:1:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h> 

Assertion failed: (BlockScope.empty() && CurAbbrevs.empty() && "Block
imbalance"), function ~BitstreamWriter, file
/Users/hendrikvonprince/develop/thirdparty/llvm-trunk/include/llvm/Bitcode/BitstreamWriter.h,
line 101.
0  ToolingTests             0x0000000106261e7e
llvm::sys::PrintStackTrace(__sFILE*) + 46
1  ToolingTests             0x000000010626322b
PrintStackTraceSignalHandler(void*) + 27
2  ToolingTests             0x0000000106263675 SignalHandler(int) + 565
3  libsystem_platform.dylib 0x00007fff8d8f15aa _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff5b5e49d8 _sigtramp + 3452908616
5  ToolingTests             0x000000010626325b raise + 27
6  ToolingTests             0x0000000106263312 abort + 18
7  ToolingTests             0x00000001062632f1 __assert_rtn + 129
8  ToolingTests             0x0000000104d7cc29
llvm::BitstreamWriter::~BitstreamWriter() + 249
9  ToolingTests             0x0000000104d6cc65
llvm::BitstreamWriter::~BitstreamWriter() + 21
10 ToolingTests             0x0000000104e4cc05 (anonymous
namespace)::SDiagsWriter::SharedState::~SharedState() + 357
11 ToolingTests             0x0000000104e4ca95 (anonymous
namespace)::SDiagsWriter::SharedState::~SharedState() + 21
12 ToolingTests             0x0000000104e4ca63 llvm::RefCountedBase<(anonymous
namespace)::SDiagsWriter::SharedState>::Release() const + 163
13 ToolingTests             0x0000000104e4c9b5
llvm::IntrusiveRefCntPtrInfo<(anonymous
namespace)::SDiagsWriter::SharedState>::release((anonymous
namespace)::SDiagsWriter::SharedState*) + 21
14 ToolingTests             0x0000000104e4c98d
llvm::IntrusiveRefCntPtr<(anonymous
namespace)::SDiagsWriter::SharedState>::release() + 45
15 ToolingTests             0x0000000104e4c955
llvm::IntrusiveRefCntPtr<(anonymous
namespace)::SDiagsWriter::SharedState>::~IntrusiveRefCntPtr() + 21
16 ToolingTests             0x0000000104e4c935
llvm::IntrusiveRefCntPtr<(anonymous
namespace)::SDiagsWriter::SharedState>::~IntrusiveRefCntPtr() + 21
17 ToolingTests             0x0000000104e4c905 (anonymous
namespace)::SDiagsWriter::~SDiagsWriter() + 53
18 ToolingTests             0x0000000104e49115 (anonymous
namespace)::SDiagsWriter::~SDiagsWriter() + 21
19 ToolingTests             0x0000000104e49139 (anonymous
namespace)::SDiagsWriter::~SDiagsWriter() + 25
20 ToolingTests             0x0000000104d93b83
clang::ChainedDiagnosticConsumer::~ChainedDiagnosticConsumer() + 291
21 ToolingTests             0x0000000104d93805
clang::ChainedDiagnosticConsumer::~ChainedDiagnosticConsumer() + 21
22 ToolingTests             0x0000000104d93829
clang::ChainedDiagnosticConsumer::~ChainedDiagnosticConsumer() + 25
23 ToolingTests             0x0000000106025355
clang::DiagnosticsEngine::setClient(clang::DiagnosticConsumer*, bool) + 261
24 ToolingTests             0x00000001060259cb
clang::DiagnosticsEngine::~DiagnosticsEngine() + 43
25 ToolingTests             0x0000000106025bb5
clang::DiagnosticsEngine::~DiagnosticsEngine() + 21
26 ToolingTests             0x0000000104e09d33
llvm::RefCountedBase<clang::DiagnosticsEngine>::Release() const + 163
27 ToolingTests             0x0000000104e09c85
llvm::IntrusiveRefCntPtrInfo<clang::DiagnosticsEngine>::release(clang::DiagnosticsEngine*)
+ 21
28 ToolingTests             0x0000000104e09c5d
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>::release() + 45
29 ToolingTests             0x0000000104e09c25
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>::~IntrusiveRefCntPtr() + 21
30 ToolingTests             0x0000000104e08365
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>::~IntrusiveRefCntPtr() + 21
31 ToolingTests             0x0000000104d4612f clang::ASTUnit::~ASTUnit() +
3503
32 ToolingTests             0x0000000104d463d5 clang::ASTUnit::~ASTUnit() + 21
33 ToolingTests             0x0000000104d463f9 clang::ASTUnit::~ASTUnit() + 25
34 ToolingTests             0x0000000104c83cf5
std::__1::__vector_base<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> >,
std::__1::allocator<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> > > >::~__vector_base() + 517
35 ToolingTests             0x0000000104c83ae5
std::__1::vector<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> >,
std::__1::allocator<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> > > >::~vector() + 21
36 ToolingTests             0x0000000104c81ab5
std::__1::vector<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> >,
std::__1::allocator<std::__1::unique_ptr<clang::ASTUnit,
std::__1::default_delete<clang::ASTUnit> > > >::~vector() + 21
37 ToolingTests             0x0000000104c7e1f6
clang::tooling::ClangToolTest_BuildASTsOnInvalidSource_Test::TestBody() + 4006
38 ToolingTests             0x0000000106116a03 void
testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) + 131
39 ToolingTests             0x000000010610600e void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) + 110
40 ToolingTests             0x00000001060f13c5 testing::Test::Run() + 197
41 ToolingTests             0x00000001060f1fdb testing::TestInfo::Run() + 219
42 ToolingTests             0x00000001060f2b07 testing::TestCase::Run() + 231
43 ToolingTests             0x00000001060f8bde
testing::internal::UnitTestImpl::RunAllTests() + 926
44 ToolingTests             0x0000000106113793 bool
testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,
bool>(testing::internal::UnitTestImpl*, bool
(testing::internal::UnitTestImpl::*)(), char const*) + 131
45 ToolingTests             0x000000010610803e bool
testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,
bool>(testing::internal::UnitTestImpl*, bool
(testing::internal::UnitTestImpl::*)(), char const*) + 110
46 ToolingTests             0x00000001060f8824 testing::UnitTest::Run() + 100
47 ToolingTests             0x000000010611e1f9 main + 89
48 libdyld.dylib            0x00007fff8f4165fd start + 1
49 libdyld.dylib            0x0000000000000002 start + 1891539462


I tried to track it down and as far as I see it, there is a missing
ExitDiagBlock() to the corresponding EnterDiagBlock in line 603 of
SerializedDiagnosticPrinter (inside the if-statement that checks on DiagLevel
!= DiagnosticsEngine::Note), but I'm not sure about it as I wasn't able to
figure out how to fix it.</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>