[clang] [clang] Fix handling of asm string literals (PR #169803)
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 7 11:24:10 PST 2026
================
@@ -245,6 +249,18 @@ ExprResult Sema::ActOnGCCAsmStmtString(Expr *Expr, bool ForAsmLabel) {
Diag(Expr->getBeginLoc(), diag::err_asm_operand_empty_string)
<< SL->getSourceRange();
}
+
+ if (!IsConstexpr &&
+ PP.getTextEncoding().getFromIBM1047Converter() != nullptr) {
+ SmallString<16> ConvertedAsm;
+ PP.getTextEncoding().getFromIBM1047Converter()->convert(SL->getString(),
+ ConvertedAsm);
+ QualType StrTy = Context.getStringLiteralArrayType(Context.CharTy,
+ ConvertedAsm.size());
+ return StringLiteral::Create(Context, ConvertedAsm,
+ StringLiteralKind::Ordinary,
+ /*Pascal*/ false, StrTy, SL->getBeginLoc());
----------------
hubert-reinterpretcast wrote:
Perhaps not directly caused by this line, but the interaction of this with diagnostic messages is problematic.
Given:
```c
void f(unsigned x) {
__asm__("\tXR %[\x68\x68\x68],%[z]"
: [\u{c7}\u{c7}\u{c7}] "=r"(x));
}
```
Compiling generates a compiler assertion failure:
```console
$ clang --target=s390x-ibm-zos -fsyntax-only asmdiag.c 2>&1 | head -n 1
Assertion failed: TokNo < getNumConcatenated() && "Invalid byte number!", file /home/hstong/.Nrtphome/.Liodine/llaixbld/dev/llvm-project/clang/lib/AST/Expr.cpp, line 1361, SourceLocation clang::StringLiteral::getLocationOfByte(unsigned int, const SourceManager &, const LangOptions &, const TargetInfo &, unsigned int *, unsigned int *) const()
```
https://github.com/llvm/llvm-project/pull/169803
More information about the cfe-commits
mailing list