diff options
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 1 |
3 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 51b5ae91d6a..0b3e60f82a8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5028,8 +5028,11 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, // Verify that we have no forward references left. If so, there was a goto // or address of a label taken, but no definition of it. Label fwd // definitions are indicated with a null substmt. - if (L->getSubStmt() != 0) + if (L->getSubStmt() != 0) { + if (!L->isUsed()) + Diag(L->getIdentLoc(), diag::warn_unused_label) << L->getName(); continue; + } // Emit error. Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName(); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4bd596b6728..40009844482 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6871,6 +6871,7 @@ ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, if (LabelDecl == 0) LabelDecl = new (Context) LabelStmt(LabLoc, LabelII, 0); + LabelDecl->setUsed(); // Create the AST node. The address of a label always has type 'void*'. return Owned(new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl, Context.getPointerType(Context.VoidTy))); @@ -7355,8 +7356,11 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, // Verify that we have no forward references left. If so, there was a goto // or address of a label taken, but no definition of it. - if (L->getSubStmt() != 0) + if (L->getSubStmt() != 0) { + if (!L->isUsed()) + Diag(L->getIdentLoc(), diag::warn_unused_label) << L->getName(); continue; + } // Emit error. Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName(); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 47ea4f2c253..24489544e06 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -994,6 +994,7 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, if (LabelDecl == 0) LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 0); + LabelDecl->setUsed(); return Owned(new (Context) GotoStmt(LabelDecl, GotoLoc, LabelLoc)); } |

