Index: lib/CodeGen/CGStmt.cpp =================================================================== --- lib/CodeGen/CGStmt.cpp +++ lib/CodeGen/CGStmt.cpp @@ -777,11 +777,6 @@ // Emit the body of the loop. llvm::BasicBlock *LoopBody = createBasicBlock("do.body"); - const SourceRange &R = S.getSourceRange(); - LoopStack.push(LoopBody, CGM.getContext(), DoAttrs, - SourceLocToDebugLoc(R.getBegin()), - SourceLocToDebugLoc(R.getEnd())); - EmitBlockWithFallThrough(LoopBody, &S); { RunCleanupsScope BodyScope(*this); @@ -790,6 +785,11 @@ EmitBlock(LoopCond.getBlock()); + const SourceRange &R = S.getSourceRange(); + LoopStack.push(LoopBody, CGM.getContext(), DoAttrs, + SourceLocToDebugLoc(R.getBegin()), + SourceLocToDebugLoc(R.getEnd())); + // C99 6.8.5.2: "The evaluation of the controlling expression takes place // after each execution of the loop body." Index: test/CodeGen/pragma-do-while.cpp =================================================================== --- /dev/null +++ test/CodeGen/pragma-do-while.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s +int test(int a[], int n) { + int i = 0; + int sum = 0; + +//CHECK-NOT: llvm.loop + +#pragma unroll 4 + do + //CHECK: do.body: + //CHECK: llvm.loop + { + a[i] = a[i] + 1; + sum = sum + a[i]; + i++; + } while (i < n); + + i = 0; + +#pragma unroll 8 + do + //CHECK: do.body{{[0-9]+}}: + //CHECK: llvm.loop + { + a[i] = a[i] + 1; + sum = sum + a[i]; + i++; + } while (i < n); + + return sum; +}