fatal error while reparsing translation unit: file '/some/path/to/header' has been modified since the precompiled header '/tmp/preamble-8ae0ef.pch' was built

Hello clang devs,

I use YouCompleteMe as a semantic completion engine for vim, which in turn uses libclang to provide completions. By default, YCM uses the 3.4 version of libclang, and all works well. However, I recently updated it to use the head version and now I’m seeing errors like that listed in the subject. I’ve been able to create a minimal reproduction - see the attached files.

To execute run commands similar to the following:

  • tar xvf clang_parse.tar.gz

  • cd clang_parse

  • mkdir obj

  • cd obj

  • cmake -D CMAKE_BUILD_TYPE=Release -G “Unix Makefiles” -D PATH_TO_LLVM_ROOT=<path to llvm head install dir - should have include and lib under here> …/src/

  • make

  • ./parse_tu

The basic test case is this:

  • Write the small cpp and h files to disk.
  • Parse the translation unit - observe that the syntax error is reported
  • Immediately reparse the TU.
  • Update the header in memory and reparse - observe that the syntax error is gone.
  • Save the header to disk and reparse. Observe the “file ‘/tmp/header_file.h’ has been modified since the precompiled header ‘/some/path/preamble-eb3c0c.pch’ was built” error.
    Am I using these methods incorrectly, or is there a bug in clang? If I’m using them incorrectly, what is the correct way to reparse a translation unit that has changed?

Thanks,
Dan

clang_parse.tar.gz (1.57 KB)

+argyrios

ping

Has anyone else seen similar errors? Is this a bug in libclang?

FYI, I’ve determined that the issue was introduced in r206309. I haven’t looked into it any further than that at this point, but thought I’d give an update in case anyone else was able to look into it.

-ds

FYI, I’ve determined that the issue was introduced in r206309. I haven’t looked into it any further than that at this point, but thought I’d give an update in case anyone else was able to look into it.

Thanks for bisecting! This is probably something to do with the changes I made to how FileManagers are shared among the ASTUnit bits. I’ll take a look.

Ben

Hey Dan,

Should be fixed in r211504. I’ll try to get your test case added to the regression tests when I have some time.

Thanks for the detailed report,

Ben

Awesome, thanks!

FYI, I finally landed a unit test based on your reproducer in r211910.

Ben