summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp27
-rw-r--r--clang/lib/Sema/TreeTransform.h7
2 files changed, 29 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 24489544e06..7acadc541c7 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -227,13 +227,35 @@ Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc,
StmtResult
Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
- SourceLocation ColonLoc, Stmt *SubStmt) {
+ SourceLocation ColonLoc, Stmt *SubStmt,
+ const AttributeList *Attr) {
+ // According to GCC docs, "the only attribute that makes sense after a label
+ // is 'unused'".
+ bool HasUnusedAttr = false;
+ llvm::OwningPtr<const AttributeList> AttrList(Attr);
+ for (const AttributeList* a = AttrList.get(); a; a = a->getNext()) {
+ if (a->getKind() == AttributeList::AT_unused) {
+ HasUnusedAttr = true;
+ } else {
+ Diag(a->getLoc(), diag::warn_label_attribute_not_unused);
+ a->setInvalid(true);
+ }
+ }
+
+ return ActOnLabelStmt(IdentLoc, II, ColonLoc, SubStmt, HasUnusedAttr);
+}
+
+StmtResult
+Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
+ SourceLocation ColonLoc, Stmt *SubStmt,
+ bool HasUnusedAttr) {
// Look up the record for this label identifier.
LabelStmt *&LabelDecl = getCurFunction()->LabelMap[II];
// If not forward referenced or defined already, just create a new LabelStmt.
if (LabelDecl == 0)
- return Owned(LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt));
+ return Owned(LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt,
+ HasUnusedAttr));
assert(LabelDecl->getID() == II && "Label mismatch!");
@@ -249,6 +271,7 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
// definition. Fill in the forward definition and return it.
LabelDecl->setIdentLoc(IdentLoc);
LabelDecl->setSubStmt(SubStmt);
+ LabelDecl->setUnusedAttribute(HasUnusedAttr);
return Owned(LabelDecl);
}
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a865348e493..71492254c6e 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -758,8 +758,9 @@ public:
StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
IdentifierInfo *Id,
SourceLocation ColonLoc,
- Stmt *SubStmt) {
- return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
+ Stmt *SubStmt, bool HasUnusedAttr) {
+ return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
+ HasUnusedAttr);
}
/// \brief Build a new "if" statement.
@@ -3562,7 +3563,7 @@ TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
// FIXME: Pass the real colon location in.
SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
- SubStmt.get());
+ SubStmt.get(), S->HasUnusedAttribute());
}
template<typename Derived>
OpenPOWER on IntegriCloud