Fixed source range for LabelDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126952 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 686ff23..f9fe0e9 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -309,17 +309,22 @@
/// 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 f37595a..6dd4707 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -2200,8 +2200,9 @@
}
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 3deb403..31f8855 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2784,7 +2784,7 @@
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 a45fa3b..ca37df9 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -245,11 +245,10 @@
}
// 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 2b69031..046d901 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -726,6 +726,8 @@
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 7c0c15c..26b325a 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -653,6 +653,7 @@
void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
VisitNamedDecl(D);
+ Record.push_back(D->isGnuLocal());
Code = serialization::DECL_LABEL;
}