forked from OSchip/llvm-project
Reorganize the return-type vs. expression checking code in
block returns; no functionality change. llvm-svn: 137884
This commit is contained in:
parent
7d92c70e6f
commit
5500ef27be
|
@ -1740,19 +1740,21 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
|
||||||
// Otherwise, verify that this result type matches the previous one. We are
|
// Otherwise, verify that this result type matches the previous one. We are
|
||||||
// pickier with blocks than for normal functions because we don't have GCC
|
// pickier with blocks than for normal functions because we don't have GCC
|
||||||
// compatibility to worry about here.
|
// compatibility to worry about here.
|
||||||
ReturnStmt *Result = 0;
|
|
||||||
const VarDecl *NRVOCandidate = 0;
|
const VarDecl *NRVOCandidate = 0;
|
||||||
if (CurBlock->ReturnType->isVoidType()) {
|
if (FnRetType->isDependentType()) {
|
||||||
if (RetValExp && !RetValExp->isTypeDependent() &&
|
// Delay processing for now. TODO: there are lots of dependent
|
||||||
(!getLangOptions().CPlusPlus || !RetValExp->getType()->isVoidType())) {
|
// types we can conclusively prove aren't void.
|
||||||
|
} else if (FnRetType->isVoidType()) {
|
||||||
|
if (RetValExp &&
|
||||||
|
!(getLangOptions().CPlusPlus &&
|
||||||
|
(RetValExp->isTypeDependent() ||
|
||||||
|
RetValExp->getType()->isVoidType()))) {
|
||||||
Diag(ReturnLoc, diag::err_return_block_has_expr);
|
Diag(ReturnLoc, diag::err_return_block_has_expr);
|
||||||
RetValExp = 0;
|
RetValExp = 0;
|
||||||
}
|
}
|
||||||
} else if (!RetValExp) {
|
} else if (!RetValExp) {
|
||||||
if (!CurBlock->ReturnType->isDependentType())
|
|
||||||
return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
|
return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
|
||||||
} else {
|
} else if (!RetValExp->isTypeDependent()) {
|
||||||
if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
|
|
||||||
// we have a non-void block with an expression, continue checking
|
// we have a non-void block with an expression, continue checking
|
||||||
|
|
||||||
// C99 6.8.6.4p3(136): The return statement is not an assignment. The
|
// C99 6.8.6.4p3(136): The return statement is not an assignment. The
|
||||||
|
@ -1772,17 +1774,15 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
|
||||||
return StmtError();
|
return StmtError();
|
||||||
}
|
}
|
||||||
RetValExp = Res.take();
|
RetValExp = Res.take();
|
||||||
|
|
||||||
if (RetValExp)
|
|
||||||
CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
|
CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (RetValExp) {
|
if (RetValExp) {
|
||||||
CheckImplicitConversions(RetValExp, ReturnLoc);
|
CheckImplicitConversions(RetValExp, ReturnLoc);
|
||||||
RetValExp = MaybeCreateExprWithCleanups(RetValExp);
|
RetValExp = MaybeCreateExprWithCleanups(RetValExp);
|
||||||
}
|
}
|
||||||
Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
|
ReturnStmt *Result = new (Context) ReturnStmt(ReturnLoc, RetValExp,
|
||||||
|
NRVOCandidate);
|
||||||
|
|
||||||
// If we need to check for the named return value optimization, save the
|
// If we need to check for the named return value optimization, save the
|
||||||
// return statement in our scope for later processing.
|
// return statement in our scope for later processing.
|
||||||
|
|
Loading…
Reference in New Issue