diff options
author | Ted Kremenek <kremenek@apple.com> | 2014-01-22 06:10:28 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2014-01-22 06:10:28 +0000 |
commit | 8a4d3a8337a6c91f2ae6613f67caff9e04d45811 (patch) | |
tree | 93f1d0d797546b029f574a674e3e96fb0266f76a /lib/Sema/SemaStmt.cpp | |
parent | e0da0232fabfc8e1abe75d2c97977de458cd4bca (diff) |
Add basic checking for returning null from functions/methods marked 'returns_nonnull'.
This involved making CheckReturnStackAddr into a static function, which
is now called by a top-level return value checking routine called
CheckReturnValExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199790 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 50a9d8111d..34a0f84e8f 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2650,7 +2650,7 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { return StmtError(); } RetValExp = Res.take(); - CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc); + CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc); } if (RetValExp) { @@ -2774,13 +2774,21 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { QualType FnRetType; QualType RelatedRetType; + const AttrVec *Attrs = 0; + bool isObjCMethod = false; + if (const FunctionDecl *FD = getCurFunctionDecl()) { FnRetType = FD->getResultType(); + if (FD->hasAttrs()) + Attrs = &FD->getAttrs(); if (FD->isNoReturn()) Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD->getDeclName(); } else if (ObjCMethodDecl *MD = getCurMethodDecl()) { FnRetType = MD->getResultType(); + isObjCMethod = true; + if (MD->hasAttrs()) + Attrs = &MD->getAttrs(); if (MD->hasRelatedResultType() && MD->getClassInterface()) { // In the implementation of a method with a related return type, the // type used to type-check the validity of return statements within the @@ -2935,7 +2943,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { RetValExp = Res.takeAs<Expr>(); } - CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc); + CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs); // C++11 [basic.stc.dynamic.allocation]p4: // If an allocation function declared with a non-throwing |