llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Abhina Sree (abhina-sree) <details> <summary>Changes</summary> This fixes https://github.com/llvm/llvm-project/issues/241514 --- Full diff: https://github.com/llvm/llvm-project/pull/243222.diff 2 Files Affected: - (modified) clang/lib/AST/Expr.cpp (+8-2) - (modified) clang/test/Sema/systemz-charset-asm-diag-loc.cpp (+1-2) ``````````diff diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 1ba2ccdf697f9..2ca8765c0cdb2 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 1daccbcd5ba85..0960fb9aad447 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 `````````` </details> https://github.com/llvm/llvm-project/pull/243222 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
