aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-18 02:08:43 +0000
committerChris Lattner <sabre@nondot.org>2011-02-18 02:08:43 +0000
commit4ae493cccbfbf122ec6ebac0e330232c22fa8489 (patch)
tree36dc74511f2ad667433c33a96c1c16bb5a8699ec /lib/Sema/SemaLookup.cpp
parent87152f783602f7548ffa28c56412d0a919cc0415 (diff)
implement basic support for __label__. I wouldn't be shocked if there are
bugs from other clients that don't expect to see a LabelDecl in a DeclStmt, but if so they should be easy to fix. This implements most of PR3429 and rdar://8287027 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r--lib/Sema/SemaLookup.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index b7740bf5c0..789f9c9f4f 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2760,10 +2760,18 @@ void Sema::LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
/*InBaseClass=*/false, Consumer, Visited);
}
-LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc) {
+/// LookupOrCreateLabel - Do a name lookup of a label with the specified name.
+/// If isLocalLabel is true, then this is a definition of an __label__ label
+/// name, otherwise it is a normal label definition or use.
+LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc,
+ bool isLocalLabel) {
// Do a lookup to see if we have a label with this name already.
- NamedDecl *Res = LookupSingleName(CurScope, II, Loc, LookupLabel,
- NotForRedeclaration);
+ NamedDecl *Res = 0;
+
+ // Local label definitions always shadow existing labels.
+ if (!isLocalLabel)
+ Res = LookupSingleName(CurScope, II, Loc, LookupLabel, NotForRedeclaration);
+
// If we found a label, check to see if it is in the same context as us. When
// in a Block, we don't want to reuse a label in an enclosing function.
if (Res && Res->getDeclContext() != CurContext)
@@ -2772,7 +2780,8 @@ LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc) {
if (Res == 0) {
// If not forward referenced or defined already, create the backing decl.
Res = LabelDecl::Create(Context, CurContext, Loc, II);
- PushOnScopeChains(Res, CurScope->getFnParent(), true);
+ PushOnScopeChains(Res, isLocalLabel ? CurScope : CurScope->getFnParent(),
+ true);
}
return cast<LabelDecl>(Res);