================
@@ -1391,8 +1391,22 @@ StringLiteral::getLocationOfByte(unsigned ByteNo, const
SourceManager &SM,
unsigned TokNumBytes = SLP.GetStringLength();
// If the byte is in this token, return the location of the byte.
- if (ByteNo < TokNumBytes ||
- (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) {
+ //
+ // The string data may have been converted to a different encoding (e.g.
+ // -fexec-charset) than the one obtained by re-lexing the source token
here,
+ // so ByteNo can lie beyond the end of the last token. In that case, clamp
+ // to the end of the last token rather than failing.
+ //
+ // FIXME: When the conversion changes the number of bytes (e.g. a
+ // multi-byte UTF-8 sequence that maps to a single byte), ByteNo no longer
+ // corresponds to the byte offset in the source spelling, so the returned
+ // location can be wrong ("drift"), and diagnostics using it may point at
+ // the wrong place. Ideally, callers would fall back to the range of the
+ // entire string literal in that case, as is done for non-literal
+ // (constant-evaluated) asm strings.
----------------
hubert-reinterpretcast wrote:
Firstly this function is used for more than just asm strings, and secondly such
a fallback is only one possibility for a fix and should be evaluated in
comparison to the cost of identifying the exact source location (in each case,
with the z/OS asm string case being somewhat niche).
https://github.com/llvm/llvm-project/pull/169803
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits