[cfe-commits] r114314 - in /cfe/trunk: lib/AST/Expr.cpp lib/Sema/SemaStmt.cpp test/Sema/warn-unused-value.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Sep 19 14:21:11 PDT 2010
Author: akirtzidis
Date: Sun Sep 19 16:21:10 2010
New Revision: 114314
URL: http://llvm.org/viewvc/llvm-project?rev=114314&view=rev
Log:
Warn when an expression result in a LabelStmt is unused.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Sema/warn-unused-value.c
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=114314&r1=114313&r2=114314&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Sep 19 16:21:10 2010
@@ -1225,9 +1225,13 @@
// 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;
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=114314&r1=114313&r2=114314&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Sep 19 16:21:10 2010
@@ -67,6 +67,9 @@
}
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;
Modified: cfe/trunk/test/Sema/warn-unused-value.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-value.c?rev=114314&r1=114313&r2=114314&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unused-value.c (original)
+++ cfe/trunk/test/Sema/warn-unused-value.c Sun Sep 19 16:21:10 2010
@@ -52,6 +52,9 @@
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.
More information about the cfe-commits
mailing list