[libclang] Internal buffers becoming corrupted on Windows?

Hello,

I am the author of an package for Emacs that brings libclang power to Emacs. It has been reported to me (here: https://github.com/Sarcasm/irony-mode/issues/134) that libclang has some issues on Windows. After some search I have identified a situation that triggers the issue consistently.

I have a pair of file, source file and header files.

foo.h

#ifndef FOO_H_

#define FOO_H_

struct Foo

{

void foobar();

};

#endif /* !FOO_H_ */

foo.cpp

#include “foo.h”

void Foo::expressionless:

foo.cpp is incomplete because it is used for requesting code-completion to libclang at the point of the pipe ‘|’.

  1. ​If I request code completion a first time, everything work as expected.

  2. If I edit foo.h to remove the method foobar() from the struct Foo, code completion still work as expected.

  3. If I restore the foobar() method, code completion breaks with the following diagnostics in this case:

    ​​​./foo.h:9:2: error: invalid preprocessing directive
    ​​./foo.h:1:2: error: unterminated conditional directive

    I have tested with some bigger changes in terms of characters, removing a big comment (~1000 chars) for example and the errors was slightly different in this case, warning about null chars in the header file.

I have the feeling that the internal buffer Clang has for the header file foo.h get corrupted somehow.

Does anyone have opinion about this?
Some places to look for or ways to debug this?

Additional information:

  • ​​This doesn’t seem to happen on Linux.

  • I just tried with the trunk (r225060), the issue is still present.

  • A slightly more detailed procedure is described here https://github.com/Sarcasm/irony-mode/issues/134#issuecomment-68412195 if someone want to reproduce the bug. It is using irony-server, a small C++ program that builds with CMake and depends on libclang. This program should be easy to get working for people already building Clang on Windows (should work with cl/clang-cl/mingw).

Thanks,

Guillaume

Is your libclang compiled with mingw or VS?

See https://github.com/Valloric/ycmd/issues/61 for windows libclang issues on ycmd.

Hi Manuel,

I believe it happens with both. The person who initially reported the issue is using Msys2 (http://sourceforge.net/projects/msys2/). On my side I’m using the Clang for Windows from (http://llvm.org/releases/download.html) and I built the trunk version using CMake + Ninja + VS 2013.

Yeah I looked at this issue and the related thread on cfe-dev (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040254.html) but I don’t think the issue is the same, there is no issue writing the file as far as I can tell.

Hi Manuel,

I believe it happens with both. The person who initially reported the issue is using Msys2 (http://sourceforge.net/projects/msys2/). On my side I’m using the Clang for Windows from (http://llvm.org/releases/download.html) and I built the trunk version using CMake + Ninja + VS 2013.

Yeah I looked at this issue and the related thread on cfe-dev (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040254.html) but I don’t think the issue is the same, there is no issue writing the file as far as I can tell.

As apparently a couple of people are using libclang on Windows with ycmd, I’m wondering whether there’s a difference in the use of libclang that explains it.