Emit an error message instead of crashing when dereferencing an incomplete pointer type.
If the ASM statement is dereferencing an incomplete pointer type, issue an error
instead of crashing.
<rdar://problem/12700799>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177915 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
index 95964e2..fc693e6 100644
--- a/lib/Sema/SemaStmtAsm.cpp
+++ b/lib/Sema/SemaStmtAsm.cpp
@@ -124,11 +124,15 @@
// Check that the output exprs are valid lvalues.
Expr *OutputExpr = Exprs[i];
- if (CheckAsmLValue(OutputExpr, *this)) {
+ if (CheckAsmLValue(OutputExpr, *this))
return StmtError(Diag(OutputExpr->getLocStart(),
- diag::err_asm_invalid_lvalue_in_output)
- << OutputExpr->getSourceRange());
- }
+ diag::err_asm_invalid_lvalue_in_output)
+ << OutputExpr->getSourceRange());
+
+ if (RequireCompleteType(OutputExpr->getLocStart(), Exprs[i]->getType(), 0))
+ return StmtError(Diag(OutputExpr->getLocStart(),
+ diag::err_dereference_incomplete_type)
+ << Exprs[i]->getType());
OutputConstraintInfos.push_back(Info);
}
@@ -181,11 +185,15 @@
InputConstraintInfos.push_back(Info);
const Type *Ty = Exprs[i]->getType().getTypePtr();
- if (Ty->isDependentType() ||
- RequireCompleteType(InputExpr->getLocStart(),
- Exprs[i]->getType(), 0))
+ if (Ty->isDependentType())
continue;
+ if (!Ty->isVoidType() || !Info.allowsMemory())
+ if (RequireCompleteType(InputExpr->getLocStart(), Exprs[i]->getType(), 0))
+ return StmtError(Diag(InputExpr->getLocStart(),
+ diag::err_dereference_incomplete_type)
+ << Exprs[i]->getType());
+
unsigned Size = Context.getTypeSize(Ty);
if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
Size))