From ad56d684259f706b7c0ae5ad9c23adb4f2926817 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 19 Apr 2009 01:04:21 +0000 Subject: [PATCH] Add location info for indirect goto. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69497 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Stmt.h | 14 +++++++++----- lib/AST/StmtSerialization.cpp | 2 +- lib/Frontend/PCHReader.cpp | 1 + lib/Frontend/PCHWriter.cpp | 1 + lib/Sema/SemaStmt.cpp | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index f665cfd582..3c1e04f47a 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -850,22 +850,26 @@ public: /// IndirectGotoStmt - This represents an indirect goto. /// class IndirectGotoStmt : public Stmt { + SourceLocation GotoLoc; Stmt *Target; - // FIXME: Add location information (e.g. SourceLocation objects). - // When doing so, update the PCH serialization routines. public: - IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), - Target((Stmt*)target){} + IndirectGotoStmt(SourceLocation gotoLoc, Expr *target) + : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), Target((Stmt*)target) {} /// \brief Build an empty indirect goto statement. explicit IndirectGotoStmt(EmptyShell Empty) : Stmt(IndirectGotoStmtClass, Empty) { } + void setGotoLoc(SourceLocation L) { GotoLoc = L; } + SourceLocation getGotoLoc() const { return GotoLoc; } + Expr *getTarget(); const Expr *getTarget() const; void setTarget(Expr *E) { Target = reinterpret_cast(E); } - virtual SourceRange getSourceRange() const { return SourceRange(); } + virtual SourceRange getSourceRange() const { + return SourceRange(GotoLoc, Target->getLocEnd()); + } static bool classof(const Stmt *T) { return T->getStmtClass() == IndirectGotoStmtClass; diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 0d920fa23e..7a37a16550 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -691,7 +691,7 @@ void IndirectGotoStmt::EmitImpl(Serializer& S) const { IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D, ASTContext& C) { Expr* Target = D.ReadOwnedPtr(C); - return new IndirectGotoStmt(Target); + return new IndirectGotoStmt(SourceLocation(), Target); } void InitListExpr::EmitImpl(Serializer& S) const { diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 6c79b8a5a5..9af75aef2b 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -415,6 +415,7 @@ unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) { unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { VisitStmt(S); + S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); S->setTarget(cast_or_null(StmtStack.back())); return 1; } diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 1efe70f270..9f22f13134 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -610,6 +610,7 @@ void PCHStmtWriter::VisitGotoStmt(GotoStmt *S) { void PCHStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { VisitStmt(S); + Writer.AddSourceLocation(S->getGotoLoc(), Record); Writer.WriteSubStmt(S->getTarget()); Code = pch::STMT_INDIRECT_GOTO; } diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 6595b88122..4a5facb39c 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -666,7 +666,7 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, } Action::OwningStmtResult -Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, +Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, ExprArg DestExp) { // Convert operand to void* Expr* E = DestExp.takeAs(); @@ -676,7 +676,7 @@ Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, if (DiagnoseAssignmentResult(ConvTy, StarLoc, Context.VoidPtrTy, ETy, E, "passing")) return StmtError(); - return Owned(new (Context) IndirectGotoStmt(E)); + return Owned(new (Context) IndirectGotoStmt(GotoLoc, E)); } Action::OwningStmtResult -- 2.40.0