Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

libclang code completion crash (libclang 3.5 & 3.6) #22811

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22811
Status NEW
Importance P normal
Reported by Matthew Nichols (dinosaurdynasty@gmail.com)
Reported on 2015-03-05 13:34:22 -0800
Last modified on 2015-03-05 13:34:22 -0800
Version 3.5
Hardware PC Linux
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments main.cpp (704 bytes, text/x-c++src)
Blocks
Blocked by
See also

Created attachment 13989 Crashes libclang

The following program causes libclang to print "libclang: crash detected in code completion" and return null for the last call:

const char program[] =
"void f(bool b);\n"
"void f(bool b) __attribute__((enable_if(b, "")));\n"
"int main() {\n"
"    bool var = true;\n"
"    f(var);\n" /* code complete inside f() */
"}\n";

#include <clang-c/Index.h>
#include <assert.h>

int main(int argc, char **argv)
{
    CXUnsavedFile file = {"test.cpp", program, sizeof program};

    CXIndex idx = clang_createIndex(1, 0);
    assert(idx);
    char* args[] = {};
    CXTranslationUnit u = clang_parseTranslationUnit(idx, "test.cpp", args, sizeof args, &file, 1, CXTranslationUnit_PrecompiledPreamble);
    assert(u);
    clang_reparseTranslationUnit(u, 0, 0, 0);
    CXCodeCompleteResults* res = clang_codeCompleteAt(u, "test.cpp", 5, 6, 0, 0, 0);
    assert(res);
}

This happens with both libclang 3.5 (1:3.5-4ubuntu2 (Ubuntu 14.10 Utopic)) and libclang 3.6 (1:3.6~+rc2-2ubuntu1~xedgers14.10.1 (Ubuntu 14.10 Utopic, https://launchpad.net/~xorg-edgers/+archive/ubuntu/ppa)). I assume it happens with other versions as well. It notably does not crash for 3.4 (1:3.4.2-10ubuntu1 on Utopic).

Quuxplusone commented 9 years ago

Attached main.cpp (704 bytes, text/x-c++src): Crashes libclang