Skip to content

Commit

Permalink
[clang][CodeGen] Don't crash on output whose size is zero. (llvm#99849)
Browse files Browse the repository at this point in the history
This fixes issue llvm#63878 caused by creating an integer with zero
bitwidth.
  • Loading branch information
yetingk committed Jul 30, 2024
1 parent 43de4e0 commit 3fcc4f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGen/inline-asm-size-zero.c
Original file line number Diff line number Diff line change
@@ -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}}
}

0 comments on commit 3fcc4f2

Please sign in to comment.