summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-03-04 13:17:22 +0000
committerMike Stump <mrs@apple.com>2009-03-04 13:17:22 +0000
commit0874160bd54fe2a9ab5315d1a68449f97af7761d (patch)
treebc8885a88457f2f5a9dc112b8d2c4d0327219653 /clang
parent0dedc114de4ff4f27caee672537fa6ba8e350e7b (diff)
downloadbcm5719-llvm-0874160bd54fe2a9ab5315d1a68449f97af7761d.tar.gz
bcm5719-llvm-0874160bd54fe2a9ab5315d1a68449f97af7761d.zip
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. llvm-svn: 66031
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp14
-rw-r--r--clang/test/CodeGen/blocks-1.c14
2 files changed, 27 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 772c9ad2c18..2f1fba02c72 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -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 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const BlockDeclRefExpr *E) {
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");
diff --git a/clang/test/CodeGen/blocks-1.c b/clang/test/CodeGen/blocks-1.c
new file mode 100644
index 00000000000..09f009c8a77
--- /dev/null
+++ b/clang/test/CodeGen/blocks-1.c
@@ -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;
+}
OpenPOWER on IntegriCloud