This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Fixed bug where ranges in spelling locations (in macro expansions) would get mangled
Needs ReviewPublic

Authored by cameron314 on May 10 2016, 2:08 PM.

Details

Reviewers
rsmith
Summary

The end location of the range would be changed into its expansion location, but the beginning of the range would stay as a spelling location. This would lead to very weird ranges spanning large parts of a file (starting in a macro until its expansion).

This bug was not previously caught because there was no way to actually obtain a spelling location via libclang (see my patch at D20125 which adds support for this), so later obtaining the start location of a range would result in an expansion location anyway, and wind up matching the expansion location that was stored in the end of the range.

Diff Detail

Event Timeline

cameron314 updated this revision to Diff 56813.May 10 2016, 2:08 PM
cameron314 retitled this revision from to [libclang] Fixed bug where ranges in spelling locations (in macro expansions) would get mangled.
cameron314 updated this object.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.
rsmith edited edge metadata.May 10 2016, 7:14 PM

I agree that this looks wrong.

Does test/Index/cindex-on-invalid.m still pass with this change? (See rL129872 in which it was added.) It looks like the problem is that we lose the information about whether we're supposed to be pointing to the start or the end of the token when we later map to the expansion location, which means that libclang's attempt to pretend that source ranges are half-open intervals rather than closed intervals breaks.

You're right, this breaks that test. The corner case that it exercises is arguably less important than breaking all spelling ranges, though. But I'm going to see if I can fix both with a little wizardry (ideally there wouldn't be open ranges in the first place, since clang doesn't really support them, but failing that we can distinguish between an inclusive and exclusive source location internally and that might be enough).

mamai added a subscriber: mamai.Mar 25 2021, 11:46 AM