summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-17 20:34:02 +0000
committerChris Lattner <sabre@nondot.org>2011-02-17 20:34:02 +0000
commitcab02a60d231b8ca4df80f88689827d8b4cea95e (patch)
tree060d42ab1daa9e8ce9b1d92c55e9014bc5d97e70 /clang/lib/Sema/SemaStmt.cpp
parent50c3c1316a0faf8b3566489aa5030a3f9ed13759 (diff)
downloadbcm5719-llvm-cab02a60d231b8ca4df80f88689827d8b4cea95e.tar.gz
bcm5719-llvm-cab02a60d231b8ca4df80f88689827d8b4cea95e.zip
Step #2/N of __label__ support: keep pushing LabelDecl forward,
making them be template instantiated in a more normal way and make them handle attributes like other decls. This fixes the used/unused label handling stuff, making it use the same infrastructure as other decls. llvm-svn: 125771
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp43
1 files changed, 18 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 2b323ef4b44..f31fbe24069 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -234,26 +234,7 @@ Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc,
StmtResult
Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
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;
- for ( ; Attr; Attr = Attr->getNext()) {
- if (Attr->getKind() == AttributeList::AT_unused) {
- HasUnusedAttr = true;
- } else {
- Diag(Attr->getLoc(), diag::warn_label_attribute_not_unused);
- Attr->setInvalid(true);
- }
- }
-
- return ActOnLabelStmt(IdentLoc, II, ColonLoc, SubStmt, HasUnusedAttr);
-}
-
-StmtResult
-Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
- SourceLocation ColonLoc, Stmt *SubStmt,
- bool HasUnusedAttr) {
+ AttributeList *Attr) {
// Look up the record for this label identifier.
LabelDecl *&TheDecl = getCurFunction()->LabelMap[II];
@@ -263,6 +244,16 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
assert(TheDecl->getIdentifier() == II && "Label mismatch!");
+ if (Attr)
+ ProcessDeclAttributeList(CurScope, TheDecl, Attr);
+
+ return ActOnLabelStmt(IdentLoc, TheDecl, ColonLoc, SubStmt);
+}
+
+StmtResult
+Sema::ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
+ SourceLocation ColonLoc, Stmt *SubStmt) {
+
// If the label was multiply defined, reject it now.
if (TheDecl->getStmt()) {
Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->getDeclName();
@@ -273,9 +264,6 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
// Otherwise, things are good. Fill in the declaration and return it.
TheDecl->setLocation(IdentLoc);
- // FIXME: Just use Decl ATTRIBUTES!
- if (HasUnusedAttr)
- TheDecl->setHasUnusedAttribute();
LabelStmt *LS = new (Context) LabelStmt(IdentLoc, TheDecl, SubStmt);
TheDecl->setStmt(LS);
TheDecl->setLocation(IdentLoc);
@@ -1038,8 +1026,6 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
StmtResult
Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
IdentifierInfo *LabelII) {
- getCurFunction()->setHasBranchIntoScope();
-
// Look up the record for this label identifier.
LabelDecl *&TheDecl = getCurFunction()->LabelMap[LabelII];
@@ -1047,6 +1033,13 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
if (TheDecl == 0)
TheDecl = LabelDecl::Create(Context, CurContext, LabelLoc, LabelII);
+ return ActOnGotoStmt(GotoLoc, LabelLoc, TheDecl);
+}
+
+StmtResult Sema::ActOnGotoStmt(SourceLocation GotoLoc,
+ SourceLocation LabelLoc,
+ LabelDecl *TheDecl) {
+ getCurFunction()->setHasBranchIntoScope();
TheDecl->setUsed();
return Owned(new (Context) GotoStmt(TheDecl, GotoLoc, LabelLoc));
}
OpenPOWER on IntegriCloud