Add location info for indirect goto.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69497 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index f665cfd..3c1e04f 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -850,22 +850,26 @@
/// 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<Stmt*>(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 0d920fa..7a37a16 100644
--- a/lib/AST/StmtSerialization.cpp
+++ b/lib/AST/StmtSerialization.cpp
@@ -691,7 +691,7 @@
IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
Expr* Target = D.ReadOwnedPtr<Expr>(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 6c79b8a..9af75ae 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -415,6 +415,7 @@
unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
VisitStmt(S);
+ S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setTarget(cast_or_null<Expr>(StmtStack.back()));
return 1;
}
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 1efe70f..9f22f13 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -610,6 +610,7 @@
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 6595b88..4a5facb 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -666,7 +666,7 @@
}
Action::OwningStmtResult
-Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
+Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc,
ExprArg DestExp) {
// Convert operand to void*
Expr* E = DestExp.takeAs<Expr>();
@@ -676,7 +676,7 @@
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