public:
ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
RetExpr((Stmt*) E), RetLoc(RL) {}
-
+
+ /// \brief Build an empty return expression.
+ explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
+
const Expr *getRetValue() const;
Expr *getRetValue();
+ void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
+
+ SourceLocation getReturnLoc() const { return RetLoc; }
+ void setReturnLoc(SourceLocation L) { RetLoc = L; }
virtual SourceRange getSourceRange() const;
STMT_CONTINUE,
/// \brief A BreakStmt record.
STMT_BREAK,
+ /// \brief A ReturnStmt record.
+ STMT_RETURN,
/// \brief A PredefinedExpr record.
EXPR_PREDEFINED,
/// \brief A DeclRefExpr record.
unsigned VisitForStmt(ForStmt *S);
unsigned VisitContinueStmt(ContinueStmt *S);
unsigned VisitBreakStmt(BreakStmt *S);
+ unsigned VisitReturnStmt(ReturnStmt *S);
unsigned VisitExpr(Expr *E);
unsigned VisitPredefinedExpr(PredefinedExpr *E);
unsigned VisitDeclRefExpr(DeclRefExpr *E);
return 0;
}
+unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
+ VisitStmt(S);
+ S->setRetValue(cast_or_null<Expr>(StmtStack.back()));
+ S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ return 1;
+}
+
unsigned PCHStmtReader::VisitExpr(Expr *E) {
VisitStmt(E);
E->setType(Reader.GetType(Record[Idx++]));
S = new (Context) BreakStmt(Empty);
break;
+ case pch::STMT_RETURN:
+ S = new (Context) ReturnStmt(Empty);
+ break;
+
case pch::EXPR_PREDEFINED:
// FIXME: untested (until we can serialize function bodies).
S = new (Context) PredefinedExpr(Empty);
StmtStack.push_back(S);
}
assert(StmtStack.size() == 1 && "Extra expressions on stack!");
+ SwitchCaseStmts.clear();
return StmtStack.back();
}
void VisitForStmt(ForStmt *S);
void VisitContinueStmt(ContinueStmt *S);
void VisitBreakStmt(BreakStmt *S);
+ void VisitReturnStmt(ReturnStmt *S);
void VisitExpr(Expr *E);
void VisitPredefinedExpr(PredefinedExpr *E);
void VisitDeclRefExpr(DeclRefExpr *E);
Code = pch::STMT_BREAK;
}
+void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
+ VisitStmt(S);
+ Writer.WriteSubStmt(S->getRetValue());
+ Writer.AddSourceLocation(S->getReturnLoc(), Record);
+ Code = pch::STMT_RETURN;
+}
+
void PCHStmtWriter::VisitExpr(Expr *E) {
VisitStmt(E);
Writer.AddTypeRef(E->getType(), Record);
}
StmtsToEmit.clear();
+ SwitchCaseIDs.clear();
}
unsigned PCHWriter::RecordSwitchCaseID(SwitchCase *S) {
// Test this without pch.
-// RUN: clang-cc -fblocks -include %S/stmts.h -fsyntax-only -emit-llvm -o - %s
+// RUN: clang-cc -fblocks -include %S/stmts.h -fsyntax-only -ast-print -o - %s
// Test with pch.
// RUN: clang-cc -emit-pch -fblocks -o %t %S/stmts.h &&
-// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -emit-llvm -o - %s
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -ast-print -o - %s
void g0(void) { f0(5); }
+int g1(int x) { return f1(x); }
break;
default:
+ switch (x >> 1) {
+ case 7:
+ // fall through
+ case 9:
+ break;
+ }
+ x += 2;
break;
}
x++;
} while (x < 10);
- for (; x < 20; ++x) ;
+ for (; x < 20; ++x) {
+ if (x == 12)
+ return;
+ }
+}
+
+int f1(int x) {
+ switch (x) {
+ case 17:
+ return 12;
+
+ default:
+ break;
+ }
+
+ return x*2;
}