Skip to content

Commit 3fcc4f2

Browse files
authored
[clang][CodeGen] Don't crash on output whose size is zero. (#99849)
This fixes issue #63878 caused by creating an integer with zero bitwidth.
1 parent 43de4e0 commit 3fcc4f2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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(OutExpr->getExprLoc(), "output size should not be zero");
27552758
}
27562759
ResultRegTypes.push_back(Ty);
27572760
// If this output is tied to an input, and if the input is larger, then
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not %clang_cc1 -S %s -verify -o -
2+
3+
void foo(void) {
4+
extern long bar[];
5+
asm ("" : "=r"(bar)); // expected-error{{output size should not be zero}}
6+
}

0 commit comments

Comments
 (0)