]> granicus.if.org Git - clang/commitdiff
Arrange to have the correct StackDepth for while statements.
authorMike Stump <mrs@apple.com>
Sat, 7 Feb 2009 18:08:12 +0000 (18:08 +0000)
committerMike Stump <mrs@apple.com>
Sat, 7 Feb 2009 18:08:12 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64021 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
lib/CodeGen/CodeGenFunction.h

index 4e2bca59ea6e727651b6bf81e68a98696c62379f..dc7722c4258ddaacfb42175a3c57592ad4a9cc12 100644 (file)
@@ -357,6 +357,14 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) {
   // it.
   llvm::BasicBlock *LoopHeader = createBasicBlock("while.cond");
   EmitBlock(LoopHeader);
+
+  // Create an exit block for when the condition fails, create a block for the
+  // body of the loop.
+  llvm::BasicBlock *ExitBlock = createBasicBlock("while.end");
+  llvm::BasicBlock *LoopBody  = createBasicBlock("while.body");
+
+  // Store the blocks to use for break and continue.
+  BreakContinuePush(ExitBlock, LoopHeader);
   
   // Evaluate the conditional in the while header.  C99 6.8.5.1: The
   // evaluation of the controlling expression takes place before each
@@ -370,18 +378,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) {
     if (C->isOne())
       EmitBoolCondBranch = false;
   
-  // Create an exit block for when the condition fails, create a block for the
-  // body of the loop.
-  llvm::BasicBlock *ExitBlock = createBasicBlock("while.end");
-  llvm::BasicBlock *LoopBody  = createBasicBlock("while.body");
-  
   // As long as the condition is true, go to the loop body.
   if (EmitBoolCondBranch)
     Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock);
   
-  // Store the blocks to use for break and continue.
-  BreakContinuePush(ExitBlock, LoopHeader);
-  
   // Emit the loop body.
   EmitBlock(LoopBody);
   EmitStmt(S.getBody());
index 90b0bf45fe05808f256c9b82d3ca0df1cba867b6..1a251d13632f2fc52973d4e085bfec9656c44a8e 100644 (file)
@@ -151,7 +151,10 @@ private:
   /// LabelMap - This keeps track of the LLVM basic block for each C label.
   llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
   
-  /// BreakContinuePush - Note a new break and continue level.
+  /// BreakContinuePush - Note a new break and continue level.  This
+  /// must be called at the stack depth of the continue block.  In
+  /// particular, this must not be called after the controlling
+  /// condition has possibly started a vla.
   void BreakContinuePush(llvm::BasicBlock *bb, llvm::BasicBlock *cb) {
     BreakContinueStack.push_back(BreakContinue(bb, cb, StackDepth,
                                                ObjCEHStack.size()));