]> granicus.if.org Git - clang/commitdiff
Fixed source range for LabelDecl.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Thu, 3 Mar 2011 18:24:14 +0000 (18:24 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Thu, 3 Mar 2011 18:24:14 +0000 (18:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126952 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/SemaStmt.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 686ff23062e5539cb8438fd756257f5281590122..f9fe0e9b85ffe2c7a096403dbebe05093e930b02 100644 (file)
@@ -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; }
index f37595a14ad5bf79d8e0fffe562547221fcdb66d..6dd47077f3a110f7d7ee667664ef6fa7cdf5560e 100644 (file)
@@ -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);
 }
 
 
index 3deb4034c538e1ff5717e75b4dafda006aa4c367..31f88554bf375a97b22c6ff3e6ab97361def7e76 100644 (file)
@@ -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);
index a45fa3b7d1c40bb371a6a890f5976086071231c0..ca37df943890150d8c137c49d3e04c02c2c3be75 100644 (file)
@@ -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);
 }
 
index 2b690310fe2652b8a814b8b826df46b2933f302a..046d901407f05862cb10666d62e5e02d5e89a100 100644 (file)
@@ -726,6 +726,8 @@ void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
 
 void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
   VisitNamedDecl(D);
+  bool IsGnuLocal = Record[Idx++];
+  D->setGnuLocal(IsGnuLocal);
 }
 
 
index 7c0c15cb0021117146276181dc03415e3572743e..26b325a5d572cc5653f94248e0214c1c362b69fc 100644 (file)
@@ -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;
 }