https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/243222
This fixes https://github.com/llvm/llvm-project/issues/241514 >From 46b909849248f8c692eb267a4192d76d2b25a579 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan <[email protected]> Date: Mon, 16 Nov 2026 15:29:54 -0500 Subject: [PATCH] Add clamping code and remove FIXME from testcase --- clang/lib/AST/Expr.cpp | 10 ++++++++-- clang/test/Sema/systemz-charset-asm-diag-loc.cpp | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 1ba2ccdf697f9d..2ca8765c0cdb26 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1391,8 +1391,14 @@ 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. + bool IsLastToken = TokNo == getNumConcatenated() - 1; + if (ByteNo < TokNumBytes || IsLastToken) { + ByteNo = std::min(ByteNo, TokNumBytes); unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); // Now that we know the offset of the token in the spelling, use the diff --git a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp index 1daccbcd5ba857..0960fb9aad4476 100644 --- a/clang/test/Sema/systemz-charset-asm-diag-loc.cpp +++ b/clang/test/Sema/systemz-charset-asm-diag-loc.cpp @@ -1,5 +1,4 @@ -// FIXME: Tracked by https://github.com/llvm/llvm-project/issues/241514 -// RUN: not --crash %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify +// RUN: %clang_cc1 -triple s390x-none-zos -fexec-charset IBM-1047 %s -std=c++23 -fsyntax-only -verify // REQUIRES: asserts // In IBM-1047, \x68 is U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA), so the _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
