[cfe-commits] r105347 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGenCXX/reference-in-block-args.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 2 14:35:17 PDT 2010
Author: fjahanian
Date: Wed Jun 2 16:35:17 2010
New Revision: 105347
URL: http://llvm.org/viewvc/llvm-project?rev=105347&view=rev
Log:
Block C++ code gen. Adds support for block reference argument
types. Executable test will be added to LLVM test suite.
(radar 8041962).
Added:
cfe/trunk/test/CodeGenCXX/reference-in-block-args.cpp
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=105347&r1=105346&r2=105347&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Jun 2 16:35:17 2010
@@ -296,8 +296,11 @@
const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E);
QualType Ty = E->getType();
if (BDRE && BDRE->isByRef()) {
- Types[i+BlockFields] = llvm::PointerType::get(BuildByRefType(BDRE->getDecl()), 0);
- } else
+ Types[i+BlockFields] =
+ llvm::PointerType::get(BuildByRefType(BDRE->getDecl()), 0);
+ } else if (BDRE && BDRE->getDecl()->getType()->isReferenceType()) {
+ Types[i+BlockFields] = llvm::PointerType::get(ConvertType(Ty), 0);
+ } else
Types[i+BlockFields] = ConvertType(Ty);
}
@@ -359,8 +362,13 @@
continue;
} else {
E = new (getContext()) DeclRefExpr(const_cast<ValueDecl*>(VD),
- VD->getType(),
- SourceLocation());
+ VD->getType().getNonReferenceType(),
+ SourceLocation());
+ if (VD->getType()->isReferenceType())
+ E = new (getContext())
+ UnaryOperator(const_cast<Expr*>(E), UnaryOperator::AddrOf,
+ getContext().getPointerType(E->getType()),
+ SourceLocation());
}
}
@@ -629,6 +637,8 @@
Ty = llvm::PointerType::get(Ty, 0);
V = Builder.CreateBitCast(V, Ty);
+ if (VD->getType()->isReferenceType())
+ V = Builder.CreateLoad(V, "tmp");
}
return V;
}
Added: cfe/trunk/test/CodeGenCXX/reference-in-block-args.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/reference-in-block-args.cpp?rev=105347&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/reference-in-block-args.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/reference-in-block-args.cpp Wed Jun 2 16:35:17 2010
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fblocks %s -emit-llvm -o %t
+// rdar: // 8041962
+
+extern "C" int printf(const char*, ...);
+
+struct ST {
+ int filler;
+ int referrer;
+};
+
+void OUTER_BLOCK(void (^fixer)(ST& ref)) {
+ ST ref = {2, 100};
+ fixer(ref);
+}
+
+void INNER_BLOCK(int (^largeDo) ()) {
+ printf("%d\n", largeDo());
+}
+
+void scan() {
+ OUTER_BLOCK(^(ST &ref) {
+ INNER_BLOCK(^() { return ref.referrer + ref.filler; });
+ });
+
+}
+
+int main() {
+ scan();
+}
More information about the cfe-commits
mailing list