[PATCH] D159086: Change begin of macro in translateSourceRange in libclang
Christoph Busold via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 29 05:43:43 PDT 2023
quic-cbusold created this revision.
quic-cbusold added a reviewer: klimek.
Herald added a subscriber: arphaman.
Herald added a project: All.
quic-cbusold requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Currently translateSourceRange changes the end location in case of
a macro. When getting the source location for a macro invocation
it therefore returns the beginning of the macro definition with
the end of the macro invocation (with everything inbetween). This
change makes it return only the location of the macro invocation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159086
Files:
clang/tools/libclang/CIndex.cpp
Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -151,11 +151,13 @@
const CharSourceRange &R) {
// We want the last character in this location, so we will adjust the
// location accordingly.
+ SourceLocation BeginLoc = R.getBegin();
SourceLocation EndLoc = R.getEnd();
bool IsTokenRange = R.isTokenRange();
if (EndLoc.isValid() && EndLoc.isMacroID() &&
!SM.isMacroArgExpansion(EndLoc)) {
CharSourceRange Expansion = SM.getExpansionRange(EndLoc);
+ BeginLoc = Expansion.getBegin();
EndLoc = Expansion.getEnd();
IsTokenRange = Expansion.isTokenRange();
}
@@ -166,7 +168,7 @@
}
CXSourceRange Result = {
- {&SM, &LangOpts}, R.getBegin().getRawEncoding(), EndLoc.getRawEncoding()};
+ {&SM, &LangOpts}, BeginLoc.getRawEncoding(), EndLoc.getRawEncoding()};
return Result;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159086.554273.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/2abc7424/attachment.bin>
More information about the cfe-commits
mailing list