[clang][CodeGen] Don't crash on output whose size is zero. (#99849)

This fixes issue #63878 caused by creating an integer with zero
bitwidth.
This commit is contained in:
Yeting Kuo
2024-07-30 13:24:14 +08:00
committed by GitHub
parent 43de4e03a3
commit 3fcc4f28ed
2 changed files with 10 additions and 1 deletions

View File

@@ -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

View File

@@ -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}}
}