[clang] [clang][CodeGen] Don't crash on output whose size is zero. (PR #99849)
Yeting Kuo via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 01:06:27 PDT 2024
https://github.com/yetingk updated https://github.com/llvm/llvm-project/pull/99849
>From 86221475bc98c0115cad564b1dc36a96544e921d Mon Sep 17 00:00:00 2001
From: Yeting Kuo <yeting.kuo at sifive.com>
Date: Mon, 22 Jul 2024 01:18:51 -0700
Subject: [PATCH] [clang][CodeGen] Don't crash on output whose size is zero.
This fixes issue #63878 caused by creating an integer with zero
bitwidth.
---
clang/lib/CodeGen/CGStmt.cpp | 5 ++++-
clang/test/CodeGen/inline-asm-size-zero.c | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CodeGen/inline-asm-size-zero.c
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index aa97f685ac7a9..e16aa3cdd5506 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(OutExpr->getExprLoc(), "output size should not be zero");
}
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-size-zero.c b/clang/test/CodeGen/inline-asm-size-zero.c
new file mode 100644
index 0000000000000..564f5207d1e71
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-size-zero.c
@@ -0,0 +1,6 @@
+// RUN: not %clang_cc1 -S %s -verify -o -
+
+void foo(void) {
+ extern long bar[];
+ asm ("" : "=r"(bar)); // expected-error{{output size should not be zero}}
+}
More information about the cfe-commits
mailing list