summaryrefslogtreecommitdiffstats
path: root/clang/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
commit9f48354b71274883ee202635a80d37e6a3f8c009 (patch)
tree9a6f3396d693116d8b3e94eb33861cdd2f2f48b8 /clang/lib/Sema/SemaStmt.cpp
parentcd43c696c95d84bebc639df900f85535ae4ae5ff (diff)
downloadbcm5719-llvm-9f48354b71274883ee202635a80d37e6a3f8c009.tar.gz
bcm5719-llvm-9f48354b71274883ee202635a80d37e6a3f8c009.zip
Don't warn for an unused label if it has 'unused' attribute. Fixes rdar://8483139.
llvm-svn: 114954
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp27
1 files changed, 25 insertions, 2 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);
}
OpenPOWER on IntegriCloud