[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 06:24:15 PST 2024
https://github.com/AdUhTkJm updated https://github.com/llvm/llvm-project/pull/119098
>From 63d966fddaef45f12610274e9e606ba70039f87c Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398666 at qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly
---
clang/lib/Sema/SemaStmtAsm.cpp | 13 ++++++++++++-
clang/test/Sema/asm.c | 14 ++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..a28ce204446bbf 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
SmallerValueMentioned |= OutSize < InSize;
}
+ // If the input is an integer register while the output is floating point,
+ // there is no way they can work together.
+ bool FPTiedToInt = false;
+ if (InputDomain != AD_FP && OutputDomain == AD_FP) {
+ FPTiedToInt = true;
+ }
+ if (InputDomain == AD_FP && OutputDomain != AD_FP) {
+ FPTiedToInt = true;
+ }
+
// If the smaller value wasn't mentioned in the asm string, and if the
// output was a register, just extend the shorter one to the size of the
// larger one.
- if (!SmallerValueMentioned && InputDomain != AD_Other &&
+ if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other &&
OutputConstraintInfos[TiedTo].allowsRegister()) {
+
// FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
// crash when the size larger than the register size. So we limit it here.
if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index a9cff5947ef5d0..d7201aa7f224aa 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -365,3 +365,17 @@ void test19(long long x)
// FIXME: This case should be supported by codegen, but it fails now.
asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}}
}
+
+// GH118892
+void test20(char x) {
+ double d;
+ float f;
+ asm ("fabs" : "=t" (d): "0" (x)); // expected-error {{unsupported inline asm: input with type 'char' matching output with type 'double'}}
+ asm ("fabs" : "=t" (x): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'char'}}
+ asm ("fabs" : "=t" (f): "0" (d)); // no-error
+ asm ("fabs" : "=t" (d): "0" (f)); // no-error
+
+ st_size64 a;
+ asm ("fabs" : "=t" (d): "0" (a)); // expected-error {{unsupported inline asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with type 'double'}}
+ asm ("fabs" : "=t" (a): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'st_size64' (aka 'struct _st_size64')}}
+}
More information about the cfe-commits
mailing list