summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp5
-rw-r--r--clang/lib/Sema/SemaExpr.cpp6
-rw-r--r--clang/lib/Sema/SemaStmt.cpp1
-rw-r--r--clang/lib/Serialization/ASTReaderStmt.cpp1
-rw-r--r--clang/lib/Serialization/ASTWriterStmt.cpp1
5 files changed, 12 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));
}
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 6e8ad4fc447..7b0845d5e7b 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -219,6 +219,7 @@ void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
S->setID(Reader.GetIdentifierInfo(Record, Idx));
S->setSubStmt(Reader.ReadSubStmt());
S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ S->setUsed(Record[Idx++]);
Reader.RecordLabelStmt(S, Record[Idx++]);
}
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 7a5b9497a82..edd8002d47c 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -213,6 +213,7 @@ void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Writer.AddIdentifierRef(S->getID(), Record);
Writer.AddStmt(S->getSubStmt());
Writer.AddSourceLocation(S->getIdentLoc(), Record);
+ Record.push_back(S->isUsed());
Record.push_back(Writer.GetLabelID(S));
Code = serialization::STMT_LABEL;
}
OpenPOWER on IntegriCloud