Skip to content

Commit 44a0091

Browse files
author
Yeting Kuo
committed
[clang][CodeGen] Don't crash on sizeless output.
This fixes issue #63878 caused by creating an integer with zero bitwidth.
1 parent 324fea9 commit 44a0091

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
27512751

27522752
if (RequiresCast) {
27532753
unsigned Size = getContext().getTypeSize(QTy);
2754-
Ty = llvm::IntegerType::get(getLLVMContext(), Size);
2754+
if (Size)
2755+
Ty = llvm::IntegerType::get(getLLVMContext(), Size);
2756+
else
2757+
CGM.Error(S.getAsmLoc(), "Output operand is sizeless!");
27552758
}
27562759
ResultRegTypes.push_back(Ty);
27572760
// If this output is tied to an input, and if the input is larger, then
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
// CHECK: error: Output operand is sizeless!
4+
void foo(void) {
5+
extern long bar[];
6+
asm ("" : "=r"(bar));
7+
}

0 commit comments

Comments
 (0)