Template instantiation for "for" loops
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71901 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index e526f5b..2daedbf 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -217,6 +217,8 @@
S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
S->setBody(StmtStack.back());
S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
return 4;
}
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index 827676a..783cd56 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -204,6 +204,8 @@
Writer.WriteSubStmt(S->getInc());
Writer.WriteSubStmt(S->getBody());
Writer.AddSourceLocation(S->getForLoc(), Record);
+ Writer.AddSourceLocation(S->getLParenLoc(), Record);
+ Writer.AddSourceLocation(S->getRParenLoc(), Record);
Code = pch::STMT_FOR;
}
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 8226dd2..2e5baee 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -589,7 +589,7 @@
}
}
}
- if (Second) {
+ if (Second && !Second->isTypeDependent()) {
DefaultFunctionArrayConversion(Second);
QualType SecondType = Second->getType();
@@ -605,7 +605,8 @@
second.release();
third.release();
body.release();
- return Owned(new (Context) ForStmt(First, Second, Third, Body, ForLoc));
+ return Owned(new (Context) ForStmt(First, Second, Third, Body, ForLoc,
+ LParenLoc, RParenLoc));
}
Action::OwningStmtResult
diff --git a/lib/Sema/SemaTemplateInstantiateStmt.cpp b/lib/Sema/SemaTemplateInstantiateStmt.cpp
index c18966a..c768234 100644
--- a/lib/Sema/SemaTemplateInstantiateStmt.cpp
+++ b/lib/Sema/SemaTemplateInstantiateStmt.cpp
@@ -42,6 +42,7 @@
OwningStmtResult VisitIfStmt(IfStmt *S);
OwningStmtResult VisitWhileStmt(WhileStmt *S);
OwningStmtResult VisitDoStmt(DoStmt *S);
+ OwningStmtResult VisitForStmt(ForStmt *S);
OwningStmtResult VisitExpr(Expr *E);
OwningStmtResult VisitLabelStmt(LabelStmt *S);
OwningStmtResult VisitGotoStmt(GotoStmt *S);
@@ -187,6 +188,32 @@
move(Cond));
}
+Sema::OwningStmtResult TemplateStmtInstantiator::VisitForStmt(ForStmt *S) {
+ // Instantiate the initialization statement
+ OwningStmtResult Init = SemaRef.InstantiateStmt(S->getInit(), TemplateArgs);
+ if (Init.isInvalid())
+ return SemaRef.StmtError();
+
+ // Instantiate the condition
+ OwningExprResult Cond = SemaRef.InstantiateExpr(S->getCond(), TemplateArgs);
+ if (Cond.isInvalid())
+ return SemaRef.StmtError();
+
+ // Instantiate the increment
+ OwningExprResult Inc = SemaRef.InstantiateExpr(S->getInc(), TemplateArgs);
+ if (Inc.isInvalid())
+ return SemaRef.StmtError();
+
+ // Instantiate the body
+ OwningStmtResult Body = SemaRef.InstantiateStmt(S->getBody(), TemplateArgs);
+ if (Body.isInvalid())
+ return SemaRef.StmtError();
+
+ return SemaRef.ActOnForStmt(S->getForLoc(), S->getLParenLoc(),
+ move(Init), move(Cond), move(Inc),
+ S->getRParenLoc(), move(Body));
+}
+
Sema::OwningStmtResult TemplateStmtInstantiator::VisitExpr(Expr *E) {
Sema::OwningExprResult Result = SemaRef.InstantiateExpr(E, TemplateArgs);
if (Result.isInvalid())