[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 7 16:48:20 PST 2024


https://github.com/AdUhTkJm updated https://github.com/llvm/llvm-project/pull/119098

>From 8269073360f882daba9d9334ea8f2b6436fe9253 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 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..770b59d0c3ebfa 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 FPBoundToInt = false;
+    if (InputDomain != AD_FP && OutputDomain == AD_FP) {
+      FPBoundToInt = true;
+    }
+    if (InputDomain == AD_FP && OutputDomain != AD_FP) {
+      FPBoundToInt = 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 && !FPBoundToInt && 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() &&



More information about the cfe-commits mailing list