Hey everyone,<div><br></div><div>first of all I just wanted to say thanks :) I've been using libclang for building my own C/C++ IDE and its great. I have, however discovered a bug (which I already submitted on llvm bugzilla but I got the impression that no one reads that :)). If I try to use clang_parseTranslationUnit on this code below:</div>
<div><br></div><div>int main() { return reinterpret_cast</div><div><br></div><div>libclang crashes.</div><div><br></div><div>This is the code I used to parse the code above:</div><div><br></div><div><div>#include <clang-c/Index.h></div>
<div><br></div><div>int main(int argc, char** argv)</div><div>{</div><div>    CXIndex index = clang_createIndex(0, 0);</div><div>    CXTranslationUnit translationUnit = clang_parseTranslationUnit(index, 0, argv, argc, 0, 0, CXTranslationUnit_None);</div>
<div><br></div><div>    clang_disposeTranslationUnit(translationUnit);</div><div>    clang_disposeIndex(index);</div><div>    return 0;</div><div>}</div></div><div><br></div><div>Am I doing anything wrong?</div><div><br></div>
<div>Here's the output from valgrind:</div><div><br></div><div><div>$ valgrind --leak-check=full ./bug_report ../main.cpp</div><div>==5926== Memcheck, a memory error detector</div><div>==5926== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.</div>
<div>==5926== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info</div><div>==5926== Command: ./bug_report ../main.cpp</div><div>==5926== </div><div>==5926== Thread 2:</div><div>==5926== Invalid read of size 1</div>
<div>==5926==    at 0x55C5FD6: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5189741: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5181324: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5182D6C: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==    by 0x5183D9E: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5184D28: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x51AAA8D: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x51B160F: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==    by 0x51B19AC: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x51ADEE3: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x51AECB1: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x515C9DF: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==  Address 0xe0 is not stack'd, malloc'd or (recently) free'd</div><div>==5926== </div><div>libclang: crash detected during parsing: {</div><div>  'source_filename' : '(null)'</div>
<div>  'command_line_args' : ['./bug_report', '../main.cpp'],</div><div>  'unsaved_files' : [],</div><div>  'options' : 0,</div><div>}</div><div>==5926== </div><div>==5926== HEAP SUMMARY:</div>
<div>==5926==     in use at exit: 13,326 bytes in 56 blocks</div><div>==5926==   total heap usage: 20,674 allocs, 20,618 frees, 29,235,096 bytes</div><div>allocated</div><div>==5926== </div><div>==5926== Thread 1:</div><div>
==5926== 47 bytes in 1 blocks are definitely lost in loss record 17 of 31</div><div>==5926==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)</div></div><div><div>==5926==    by 0x5A71708: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17)</div>
<div>==5926==    by 0x5A730E4: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17)</div>
<div>==5926==    by 0x5A731FC: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17)</div>
<div>==5926==    by 0x6D4101B: llvm::sys::Path::Path(llvm::StringRef) (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x4F4788C: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x4F39080: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==    by 0x6D32DDE: llvm::CrashRecoveryContext::RunSafely(void (*)(void*), void*) (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x6D32E13: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div>
<div>==5926==    by 0x6D583CC: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x7610E99: start_thread (pthread_create.c:308)</div><div>==5926==    by 0x5DAB4BC: clone (clone.S:112)</div><div>
==5926== </div><div>==5926== 3,108 (1,104 direct, 2,004 indirect) bytes in 1 blocks are definitely lost in loss record 29 of 31</div><div>==5926==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)</div>
<div>==5926==    by 0x5026BAB: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x50290D4: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x502A3F6: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x4F39144: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==    by 0x6D32DDE: llvm::CrashRecoveryContext::RunSafely(void(*)(void*), void*) (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x6D32E13: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div>
<div>==5926==    by 0x6D583CC: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x7610E99: start_thread (pthread_create.c:308)</div><div>==5926==    by 0x5DAB4BC: clone (clone.S:112)</div><div>
==5926== </div><div>==5926== 8,648 (448 direct, 8,200 indirect) bytes in 1 blocks are definitely lost in loss record 31 of 31</div></div><div><div>==5926==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)</div>
<div>==5926==    by 0x51534AD: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5153F48: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5152004: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x5026FFF: ??? (in /usr/lib/libclang.so.1)</div>
<div>==5926==    by 0x50290D4: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x502A3F6: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x4F39144: ??? (in /usr/lib/libclang.so.1)</div><div>==5926==    by 0x6D32DDE: llvm::CrashRecoveryContext::RunSafely(void (*)(void*), void*) (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div>
<div>==5926==    by 0x6D32E13: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x6D583CC: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-3.1.so.1)</div><div>==5926==    by 0x7610E99: start_thread (pthread_create.c:308)</div>
<div>==5926== </div><div>==5926== LEAK SUMMARY:</div><div>==5926==    definitely lost: 1,599 bytes in 3 blocks</div><div>==5926==    indirectly lost: 10,204 bytes in 42 blocks</div><div>==5926==      possibly lost: 0 bytes in 0 blocks</div>
<div>==5926==    still reachable: 1,523 bytes in 11 blocks</div><div>==5926==         suppressed: 0 bytes in 0 blocks</div><div>==5926== Reachable blocks (those to which a pointer was found) are not shown.</div><div>==5926== To see them, rerun with: --leak-check=full --show-reachable=yes</div>
<div>==5926== </div><div>==5926== For counts of detected and suppressed errors, rerun with: -v</div><div>==5926== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 2 from 2)</div></div>