Page MenuHomePhabricator

Show inclusions from a preamble in clang_getInclusions.
ClosedPublic

Authored by erikjv on Nov 4 2015, 4:30 AM.

Details

Summary

When reparsing a translation unit with preamble generation turned on,
no includes are found. This is due to the fact that all SLocs from
AST/PCH files are skipped as they are 'loaded', and inclusions from a
preamble are also 'loaded'. So, in case a file has a preamble, it first
needs to process those loaded inclusions, and then check for any local
inclusions. This latter one is for any includes that are not part of the
preamble, like includes half-way through a file.

Diff Detail

Repository
rL LLVM

Event Timeline

erikjv updated this revision to Diff 39187.Nov 4 2015, 4:30 AM
erikjv retitled this revision from to Show inclusions from a preamble in clang_getInclusions..
erikjv updated this object.
erikjv added a reviewer: klimek.
erikjv added a subscriber: cfe-commits.

I've seen this bug too. Generally this patch looks good to me.

Could you also add a test for includes half-way through a file case?

tools/c-index-test/c-index-test.c
1567 ↗(On Diff #39187)

This is not a very good idea to add this code here IMO. There are probably some tests that use this function with CINDEXTEST_EDITING set, which could potentially hide some parsing vs. reparsing bugs. I'd suggest to use something like perform_test_reparse_source instead.

bkramer accepted this revision.Jan 6 2016, 5:41 AM
bkramer edited edge metadata.

LGTM, thanks for the fix!

tools/libclang/CIndexInclusionStack.cpp
32 ↗(On Diff #39187)

There's already a wild mix of coding styles in this file, let's not add more of them. bool HasPreamble is the preferred style.

This revision is now accepted and ready to land.Jan 6 2016, 5:41 AM
This revision was automatically updated to reflect the committed changes.