https://github.com/yetingk created 
https://github.com/llvm/llvm-project/pull/99849

This fixes issue #63878 caused by creating an integer with zero bitwidth.

>From 44a0091b3e28b5c36f2eebe9e91d5c57f25a5d32 Mon Sep 17 00:00:00 2001
From: Yeting Kuo <yeting....@sifive.com>
Date: Mon, 22 Jul 2024 01:18:51 -0700
Subject: [PATCH] [clang][CodeGen] Don't crash on sizeless output.

This fixes issue #63878 caused by creating an integer with zero
bitwidth.
---
 clang/lib/CodeGen/CGStmt.cpp             | 5 ++++-
 clang/test/CodeGen/inline-asm-sizeless.c | 7 +++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/inline-asm-sizeless.c

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index aa97f685ac7a9..92955e6cf4c96 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2751,7 +2751,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
       if (RequiresCast) {
         unsigned Size = getContext().getTypeSize(QTy);
-        Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+        if (Size)
+          Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+        else
+          CGM.Error(S.getAsmLoc(), "Output operand is sizeless!");
       }
       ResultRegTypes.push_back(Ty);
       // If this output is tied to an input, and if the input is larger, then
diff --git a/clang/test/CodeGen/inline-asm-sizeless.c 
b/clang/test/CodeGen/inline-asm-sizeless.c
new file mode 100644
index 0000000000000..29c1fc5b0b8f7
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-sizeless.c
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: Output operand is sizeless!
+void foo(void) {
+    extern long bar[];
+    asm ("" : "=r"(bar));
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to