diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-14 07:37:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-14 07:37:35 +0000 |
commit | 026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8 (patch) | |
tree | 60f69baca2a6bbbe35475d1155cf5ec41b7b0df1 /lib/Sema/SemaStmt.cpp | |
parent | 90e150d7f40e24ed6f8d268e7d83b2f15153c1ee (diff) |
Several related changes:
1) implement parser and sema support for reading and verifying attribute(warnunusedresult).
2) rename hasLocalSideEffect to isUnusedResultAWarning, inverting the sense
of its result.
3) extend isUnusedResultAWarning to directly return the loc and range
info that should be reported to the user. Make it substantially more
precise in some cases than what was previously reported.
4) teach isUnusedResultAWarning about CallExpr to decls that are
pure/const/warnunusedresult, fixing a fixme.
5) change warn_attribute_wrong_decl_type to not pass in english strings, instead,
pass in integers and use %select.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64543 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index bfa1c5e6d0..c2c1a0f56f 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -95,25 +95,17 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, Expr *E = dyn_cast<Expr>(Elts[i]); if (!E) continue; - // Warn about expressions with unused results. - if (E->hasLocalSideEffect() || E->getType()->isVoidType()) + // Warn about expressions with unused results if they are non-void and if + // this not the last stmt in a stmt expr. + if (E->getType()->isVoidType() || (isStmtExpr && i == NumElts-1)) continue; - // The last expr in a stmt expr really is used. - if (isStmtExpr && i == NumElts-1) + SourceLocation Loc; + SourceRange R1, R2; + if (!E->isUnusedResultAWarning(Loc, R1, R2)) continue; - - /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in - /// a context where the result is unused. Emit a diagnostic to warn about - /// this. - if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) - Diag(BO->getOperatorLoc(), diag::warn_unused_expr) - << BO->getLHS()->getSourceRange() << BO->getRHS()->getSourceRange(); - else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) - Diag(UO->getOperatorLoc(), diag::warn_unused_expr) - << UO->getSubExpr()->getSourceRange(); - else - Diag(E->getExprLoc(), diag::warn_unused_expr) << E->getSourceRange(); + + Diag(Loc, diag::warn_unused_expr) << R1 << R2; } return Owned(new (Context) CompoundStmt(Context, Elts, NumElts, L, R)); |