This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location
Needs ReviewPublic

Authored by cameron314 on May 10 2016, 12:59 PM.

Details

Reviewers
akyrtzi
rsmith
Summary

All the libclang functions for expanding a location, namely clang_getExpansionLocation, clang_getPresumedLocation, clang_getInstantiationLocation, and most surprisingly clang_getSpellingLocation return expansion locations, not spelling locations. As it turns out, there is no way to get a spelling location via libclang. This patch adds such a function.

Note that there's a FIXME in clang_getSpellingLocation about this, but changing clang_getSpellingLocation to actually return a spelling location would almost certainly break a large body of existing (third-party) code, mostly in subtle ways. I think it's better to introduce a new function, though I know it's ugly. But, this is what we've been using for the past year, and we've gotten quite comfortable with it.

Diff Detail

Event Timeline

cameron314 retitled this revision from to [libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location.
cameron314 updated this object.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.
rsmith edited edge metadata.May 10 2016, 7:07 PM

Ugh. Yes. I suppose it's too late to make this actually do the right thing. @akyrtzi, what do you think?

Please add a test for this (see unittests/libclang/LibclangTest.cpp).

Ah, I was wondering where the tests were. I found this in the CMake file:

# FIXME: libclang unit tests are disabled on Windows due
# to failures, mostly in libclang.VirtualFileOverlay_*.
if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) 
  add_subdirectory(libclang)
endif()

I'll ignore the VFO failures for now, and add a new test for clang_getRealSpellingLocation :-)

cameron314 updated this revision to Diff 56916.May 11 2016, 8:12 AM
cameron314 edited edge metadata.

I've added a unit test.

cameron314 updated this revision to Diff 56917.May 11 2016, 8:30 AM
mamai added a subscriber: mamai.Mar 25 2021, 11:46 AM