[clang] [clang][CodeGen] Don't crash on sizeless output. (PR #99849)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 22 01:46:18 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Yeting Kuo (yetingk)
<details>
<summary>Changes</summary>
This fixes issue #<!-- -->63878 caused by creating an integer with zero bitwidth.
---
Full diff: https://github.com/llvm/llvm-project/pull/99849.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGStmt.cpp (+4-1)
- (added) clang/test/CodeGen/inline-asm-sizeless.c (+7)
``````````diff
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));
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/99849
More information about the cfe-commits
mailing list