aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-09-28 14:54:07 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-09-28 14:54:07 +0000
commit1a18600b85aaa691122983dd8dcf4225cfc9ef68 (patch)
treeae18cba7044d0436807c534f49996cc0ca91e3c0 /lib/Sema/SemaStmt.cpp
parentedadecc012dd6bc0bb008a89f0eaccd5c4c1ff64 (diff)
Don't warn for an unused label if it has 'unused' attribute. Fixes rdar://8483139.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114954 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 24489544e0..7acadc541c 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/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);
}