]> granicus.if.org Git - clang/commitdiff
Fixup blocks codegen for { __block i; i = rhs(); }, we want the rhs
authorMike Stump <mrs@apple.com>
Thu, 21 May 2009 21:05:15 +0000 (21:05 +0000)
committerMike Stump <mrs@apple.com>
Thu, 21 May 2009 21:05:15 +0000 (21:05 +0000)
evaluated first.  This can also improve codegen just a bit as we might
have another register to play with for the evaluation of the rhs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72226 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/blocks-seq.c [new file with mode: 0644]

index 05573d6aec342724d8252076257f3c74a8346f8e..01dd94c274bef84042ee75012d183fd0ac779afe 100644 (file)
@@ -1189,8 +1189,10 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,unsigned UICmpOpc,
 }
 
 Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
-  LValue LHS = EmitLValue(E->getLHS());
+  // __block variables need to have the rhs evaluated first, plus
+  // this should improve codegen just a little.
   Value *RHS = Visit(E->getRHS());
+  LValue LHS = EmitLValue(E->getLHS());
   
   // Store the value into the LHS.  Bit-fields are handled specially
   // because the result is altered by the store, i.e., [C99 6.5.16p1]
diff --git a/test/CodeGen/blocks-seq.c b/test/CodeGen/blocks-seq.c
new file mode 100644 (file)
index 0000000..eb4990a
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fblocks -triple x86_64-apple-darwin10 -emit-llvm -o %t %s &&
+// RUN: grep '%call = call i32 (...)\* @rhs()' %t | count 1 &&
+// If this fails, see about sliding %4 and %5...
+// RUN: grep '%forwarding1 = getelementptr %0\* %i, i32 0, i32 1' %t | count 1 &&
+// RUN: grep '%4 = bitcast i8\*\* %forwarding1 to %0\*\*' %t | count 1 &&
+// RUN: grep '%5 = load %0\*\* %4' %t | count 1
+
+int rhs();
+
+void foo() {
+  __block int i;
+  i = rhs();
+}