[cfe-commits] r69355 - in /cfe/trunk: include/clang/AST/Stmt.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/stmts.c test/PCH/stmts.h
Douglas Gregor
dgregor at apple.com
Fri Apr 17 09:34:58 PDT 2009
Author: dgregor
Date: Fri Apr 17 11:34:57 2009
New Revision: 69355
URL: http://llvm.org/viewvc/llvm-project?rev=69355&view=rev
Log:
PCH support for return statements.
Optimize PCH encoding for switch-case statements slightly, by making
the switch-case numbering local to a particular statement.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/PCH/stmts.c
cfe/trunk/test/PCH/stmts.h
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Apr 17 11:34:57 2009
@@ -931,9 +931,16 @@
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;
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 17 11:34:57 2009
@@ -397,6 +397,8 @@
STMT_CONTINUE,
/// \brief A BreakStmt record.
STMT_BREAK,
+ /// \brief A ReturnStmt record.
+ STMT_RETURN,
/// \brief A PredefinedExpr record.
EXPR_PREDEFINED,
/// \brief A DeclRefExpr record.
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 17 11:34:57 2009
@@ -256,6 +256,7 @@
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);
@@ -398,6 +399,13 @@
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++]));
@@ -2172,6 +2180,10 @@
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);
@@ -2311,6 +2323,7 @@
StmtStack.push_back(S);
}
assert(StmtStack.size() == 1 && "Extra expressions on stack!");
+ SwitchCaseStmts.clear();
return StmtStack.back();
}
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 17 11:34:57 2009
@@ -458,6 +458,7 @@
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);
@@ -592,6 +593,13 @@
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);
@@ -1822,6 +1830,7 @@
}
StmtsToEmit.clear();
+ SwitchCaseIDs.clear();
}
unsigned PCHWriter::RecordSwitchCaseID(SwitchCase *S) {
Modified: cfe/trunk/test/PCH/stmts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/stmts.c?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/test/PCH/stmts.c (original)
+++ cfe/trunk/test/PCH/stmts.c Fri Apr 17 11:34:57 2009
@@ -1,8 +1,9 @@
// 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); }
Modified: cfe/trunk/test/PCH/stmts.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/stmts.h?rev=69355&r1=69354&r2=69355&view=diff
==============================================================================
--- cfe/trunk/test/PCH/stmts.h (original)
+++ cfe/trunk/test/PCH/stmts.h Fri Apr 17 11:34:57 2009
@@ -17,6 +17,13 @@
break;
default:
+ switch (x >> 1) {
+ case 7:
+ // fall through
+ case 9:
+ break;
+ }
+ x += 2;
break;
}
@@ -32,5 +39,20 @@
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;
}
More information about the cfe-commits
mailing list