[cfe-commits] r54100 - in /cfe/trunk/lib/CodeGen: CGExprScalar.cpp CGStmt.cpp CodeGenFunction.h
Chris Lattner
sabre at nondot.org
Sat Jul 26 13:23:23 PDT 2008
Author: lattner
Date: Sat Jul 26 15:23:23 2008
New Revision: 54100
URL: http://llvm.org/viewvc/llvm-project?rev=54100&view=rev
Log:
implement codegen support for labels at the end of stmtexprs.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=54100&r1=54099&r2=54100&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Jul 26 15:23:23 2008
@@ -583,7 +583,8 @@
}
Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) {
- return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getScalarVal();
+ return CGF.EmitCompoundStmt(*E->getSubStmt(),
+ !E->getType()->isVoidType()).getScalarVal();
}
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=54100&r1=54099&r2=54100&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Jul 26 15:23:23 2008
@@ -86,8 +86,6 @@
RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
llvm::Value *AggLoc, bool isAggVol) {
// FIXME: handle vla's etc.
- if (S.body_empty() || !isa<Expr>(S.body_back())) GetLast = false;
-
CGDebugInfo *DI = CGM.getDebugInfo();
if (DI) {
if (S.getLBracLoc().isValid())
@@ -108,7 +106,17 @@
if (!GetLast)
return RValue::get(0);
- return EmitAnyExpr(cast<Expr>(S.body_back()), AggLoc);
+ // We have to special case labels here. They are statements, but when put at
+ // the end of a statement expression, they yield the value of their
+ // subexpression. Handle this by walking through all labels we encounter,
+ // emitting them before we evaluate the subexpr.
+ const Stmt *LastStmt = S.body_back();
+ while (const LabelStmt *LS = dyn_cast<LabelStmt>(LastStmt)) {
+ EmitLabel(*LS);
+ LastStmt = LS->getSubStmt();
+ }
+
+ return EmitAnyExpr(cast<Expr>(LastStmt), AggLoc);
}
void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) {
@@ -130,10 +138,14 @@
Builder.SetInsertPoint(BB);
}
-void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
+void CodeGenFunction::EmitLabel(const LabelStmt &S) {
llvm::BasicBlock *NextBB = getBasicBlockForLabel(&S);
-
EmitBlock(NextBB);
+}
+
+
+void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
+ EmitLabel(S);
EmitStmt(S.getSubStmt());
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=54100&r1=54099&r2=54100&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Jul 26 15:23:23 2008
@@ -359,6 +359,7 @@
void EmitStmt(const Stmt *S);
RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
llvm::Value *AggLoc = 0, bool isAggVol = false);
+ void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
void EmitLabelStmt(const LabelStmt &S);
void EmitGotoStmt(const GotoStmt &S);
void EmitIfStmt(const IfStmt &S);
More information about the cfe-commits
mailing list