diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index aa97f685ac7a..e16aa3cdd550 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(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 diff --git a/clang/test/CodeGen/inline-asm-size-zero.c b/clang/test/CodeGen/inline-asm-size-zero.c new file mode 100644 index 000000000000..564f5207d1e7 --- /dev/null +++ b/clang/test/CodeGen/inline-asm-size-zero.c @@ -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}} +}