[cfe-dev] clang_parseTranslationUnit

Samuel Williams via cfe-dev cfe-dev at lists.llvm.org
Sat Sep 12 00:13:45 PDT 2020


Hello,

I maintain ffi-clang for Ruby.

We recently started reworking the gem to support llvm 10.0 - the last
supported release was llvm 4.0 which was a while ago.

So, most things seem to be working fine - we have several hundred
tests. However, I had some trouble with `clang_parseTranslationUnit`.

It seems like it's not picking up the system include directories.

We have the following code to parse a translation unit:

let(:filename) { fixture_path("completion.cpp") }
let(:translation_unit) { Index.new.parse_translation_unit(filename) }

`parse_translation_unit` basically calls clang_parseTranslationUnit

But, in llvm 4.0, it seems this automatically detected file type and
exposed stdc++ headers. But with llvm 10.0 - it seems I need to
manually add header search paths. Doing something like the following
worked:

let(:includes) {[
  "-I/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0",
  "-I/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/x86_64-pc-linux-gnu",
  "-I/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/backward",
  "-I/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include",
  "-I/usr/local/include",
  "-I/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include-fixed",
"-I/usr/include",
]}
let(:translation_unit) { Index.new.parse_translation_unit(filename,
[*includes]) }

I don't know if there is a better set of arguments to pass to
`clang_parseTranslationUnit` that behaves the same was as before i.e.
implicitly figures out what include paths to use.

By the way, I figured out what include paths to use by running:

echo "" | clang++ -v -x c++ -E -

So, it's definitely the case that at least `clang++` knows where those
headers are.

Thanks!
Samuel


More information about the cfe-dev mailing list