summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-09-19 21:21:10 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-09-19 21:21:10 +0000
commit90963413104034cd883c93e08f7b30949429b169 (patch)
tree044e423c1ecd45cc94b91f1b887c344fdc715e89
parent7b8d2ae9129a68dfb058f209f2fec4db032639cf (diff)
downloadbcm5719-llvm-90963413104034cd883c93e08f7b30949429b169.tar.gz
bcm5719-llvm-90963413104034cd883c93e08f7b30949429b169.zip
Warn when an expression result in a LabelStmt is unused.
llvm-svn: 114314
-rw-r--r--clang/lib/AST/Expr.cpp6
-rw-r--r--clang/lib/Sema/SemaStmt.cpp3
-rw-r--r--clang/test/Sema/warn-unused-value.c3
3 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 4c6822c041f..b31ec2314dc 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1225,9 +1225,13 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
// however, if the result of the stmt expr is dead, we don't want to emit a
// warning.
const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
- if (!CS->body_empty())
+ if (!CS->body_empty()) {
if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
+ if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back()))
+ if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt()))
+ return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
+ }
if (getType()->isVoidType())
return false;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 8ec12a460db..47ea4f2c253 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -67,6 +67,9 @@ void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) {
}
void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
+ if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
+ return DiagnoseUnusedExprResult(Label->getSubStmt());
+
const Expr *E = dyn_cast_or_null<Expr>(S);
if (!E)
return;
diff --git a/clang/test/Sema/warn-unused-value.c b/clang/test/Sema/warn-unused-value.c
index 1a7e745785b..7c36b6983e7 100644
--- a/clang/test/Sema/warn-unused-value.c
+++ b/clang/test/Sema/warn-unused-value.c
@@ -52,6 +52,9 @@ void pr4806() {
volatile int* pj = &j;
*pi; // expected-warning {{expression result unused}}
*pj;
+
+ foo_label:
+ i; // expected-warning {{expression result unused}}
}
// Don't warn about unused '||', '&&' expressions that contain assignments.
OpenPOWER on IntegriCloud