From 58919e1f982da4f57356afd38bc86b13d84199df Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Wed, 4 Mar 2009 13:17:22 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66031 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBlocks.cpp | 14 +++++++++++++- test/CodeGen/blocks-1.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/blocks-1.c diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 772c9ad2c1..2f1fba02c7 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/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 +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/test/CodeGen/blocks-1.c b/test/CodeGen/blocks-1.c new file mode 100644 index 0000000000..09f009c8a7 --- /dev/null +++ b/test/CodeGen/blocks-1.c @@ -0,0 +1,14 @@ +// RUN: clang %s -emit-llvm -o %t -fblocks -f__block +#include + +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; +} -- 2.50.1