Open delcypher opened 2 months ago
@llvm/issue-subscribers-bug
Author: Dan Liew (delcypher)
Hmm actually this might be a misunderstanding on my part. According to https://clang.llvm.org/docs/InternalsManual.html#sourcerange-and-charsourcerange . The begin and end sourcelocations in a range are supposed to point at the beginning of their respective tokens.
Problem
DeclRefExpr::getEndLoc()
returns the sameSourceLocation
asDeclRefExpr::getStartLoc()
. This means callingDeclRefExpr::getSourceRange()
doesn't return a useful range for diagnostic emission.I would have expected
DeclRefExpr::getEndLoc()
to return a SourceLocation that points to the last character of the identifier in the source code.Cause
Calling
DeclRefExpr::getSourceRange()
on aDeclRefExpr
effectively returns a 1 character range because it usesand
DeclRefExpr::getEndLoc()
is implemented asThis effectively returns
DeclRefExpr::getLocation()
whenDeclarationNameInfo::Name.getNameKind()
isDeclarationName::Identifier
because of ...DeclRefExpr::getLocation()
effectively returns the same location asDeclRefExpr::getStartLoc()
.Fixing
We might be able to fix this by doing something like...
Not sure if this really works in the presence of macros.