aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbramo Bagnara <abramo.bagnara@gmail.com>2011-03-03 18:24:14 +0000
committerAbramo Bagnara <abramo.bagnara@gmail.com>2011-03-03 18:24:14 +0000
commit203548ba4b72e7e59320d352afc1eb0b5ab131de (patch)
tree6f42c316fb3723c23233ba3547002bd4831502de
parent48b89590f61575cbf365ba996a2bd1ba1561a4ab (diff)
Fixed source range for LabelDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126952 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h17
-rw-r--r--lib/AST/Decl.cpp5
-rw-r--r--lib/Sema/SemaLookup.cpp2
-rw-r--r--lib/Sema/SemaStmt.cpp5
-rw-r--r--lib/Serialization/ASTReaderDecl.cpp2
-rw-r--r--lib/Serialization/ASTWriterDecl.cpp1
6 files changed, 20 insertions, 12 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 686ff23062..f9fe0e9b85 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -309,17 +309,22 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
/// location of the statement. For GNU local labels (__label__), the decl
/// location is where the __label__ is.
class LabelDecl : public NamedDecl {
- LabelStmt *TheStmt;
- LabelDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *II, LabelStmt *S)
- : NamedDecl(Label, DC, L, II), TheStmt(S) {}
+ llvm::PointerIntPair<LabelStmt *, 1, bool> StmtAndGnuLocal;
+ LabelDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *II,
+ LabelStmt *S, bool isGnuLocal)
+ : NamedDecl(Label, DC, L, II), StmtAndGnuLocal(S, isGnuLocal) {}
public:
static LabelDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, IdentifierInfo *II);
+ SourceLocation L, IdentifierInfo *II,
+ bool isGnuLocal = false);
- LabelStmt *getStmt() const { return TheStmt; }
- void setStmt(LabelStmt *T) { TheStmt = T; }
+ LabelStmt *getStmt() const { return StmtAndGnuLocal.getPointer(); }
+ void setStmt(LabelStmt *T) { StmtAndGnuLocal.setPointer(T); }
+ bool isGnuLocal() const { return StmtAndGnuLocal.getInt(); }
+ void setGnuLocal(bool V = true) { StmtAndGnuLocal.setInt(V); }
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const LabelDecl *D) { return true; }
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index f37595a14a..6dd47077f3 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -2200,8 +2200,9 @@ TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
}
LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, IdentifierInfo *II) {
- return new (C) LabelDecl(DC, L, II, 0);
+ SourceLocation L, IdentifierInfo *II,
+ bool isGnuLocal) {
+ return new (C) LabelDecl(DC, L, II, 0, isGnuLocal);
}
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 3deb4034c5..31f88554bf 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2784,7 +2784,7 @@ 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);
+ Res = LabelDecl::Create(Context, CurContext, Loc, II, isLocalLabel);
Scope *S = isLocalLabel ? CurScope : CurScope->getFnParent();
assert(S && "Not in a function?");
PushOnScopeChains(Res, S, true);
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index a45fa3b7d1..ca37df9438 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -245,11 +245,10 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
}
// Otherwise, things are good. Fill in the declaration and return it.
- TheDecl->setLocation(IdentLoc);
-
LabelStmt *LS = new (Context) LabelStmt(IdentLoc, TheDecl, SubStmt);
TheDecl->setStmt(LS);
- TheDecl->setLocation(IdentLoc);
+ if (!TheDecl->isGnuLocal())
+ TheDecl->setLocation(IdentLoc);
return Owned(LS);
}
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 2b690310fe..046d901407 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -726,6 +726,8 @@ void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
VisitNamedDecl(D);
+ bool IsGnuLocal = Record[Idx++];
+ D->setGnuLocal(IsGnuLocal);
}
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index 7c0c15cb00..26b325a5d5 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -653,6 +653,7 @@ void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
VisitNamedDecl(D);
+ Record.push_back(D->isGnuLocal());
Code = serialization::DECL_LABEL;
}