[cfe-commits] r66031 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGen/blocks-1.c

Mike Stump mrs at apple.com
Wed Mar 4 05:17:26 PST 2009


Author: mrs
Date: Wed Mar  4 07:17:22 2009
New Revision: 66031

URL: http://llvm.org/viewvc/llvm-project?rev=66031&view=rev
Log:
Add __block codegen testcase.  We introduce a temporary flag to enable
codegen, until such time as codegen is complete enough to turn on with
-fblocks.

Added:
    cfe/trunk/test/CodeGen/blocks-1.c
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=66031&r1=66030&r2=66031&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Mar  4 07:17:22 2009
@@ -21,6 +21,18 @@
 using namespace clang;
 using namespace CodeGen;
 
+// Temporary code to enable testing of __block variables
+// #include "clang/Frontend/CompileOptions.h"
+#include "llvm/Support/CommandLine.h"
+static llvm::cl::opt<bool>
+Enable__block("f__block",
+              // See all the FIXMEs for the various work that needs to be done
+              llvm::cl::desc("temporary option to turn on __block precessing "
+                             "even though the code isn't done yet"),
+              llvm::cl::ValueDisallowed, llvm::cl::AllowInverse,
+              llvm::cl::ZeroOrMore);
+
+
 llvm::Constant *CodeGenFunction::BuildDescriptorBlockDecl(uint64_t Size) {
   const llvm::PointerType *PtrToInt8Ty
     = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
@@ -448,7 +460,7 @@
   Ty = CGM.getTypes().ConvertType(E->getDecl()->getType());
 
   // FIXME: add support for copy/dispose helpers.
-  if (1 && E->isByRef())
+  if (!Enable__block && E->isByRef())
     ErrorUnsupported(E, "__block variable in block literal");
   else if (E->getType()->isBlockPointerType())
     ErrorUnsupported(E, "block pointer in block literal");

Added: cfe/trunk/test/CodeGen/blocks-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks-1.c?rev=66031&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (added)
+++ cfe/trunk/test/CodeGen/blocks-1.c Wed Mar  4 07:17:22 2009
@@ -0,0 +1,14 @@
+// RUN: clang %s -emit-llvm -o %t -fblocks -f__block
+#include <stdio.h>
+
+int main() {
+    __block int a;
+    int b=2;
+    a=1;
+    printf("a is %d, b is %d\n", a, b);
+    ^{ a = 10; printf("a is %d, b is %d\n", a, b); }();
+    printf("a is %d, b is %d\n", a, b);
+    a = 1;
+    printf("a is %d, b is %d\n", a, b);
+    return 0;
+}





More information about the cfe-commits mailing list