[cfe-commits] r132657 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaStmt.cpp test/CodeGenObjCXX/block-in-template-inst.mm
Douglas Gregor
dgregor at apple.com
Sat Jun 4 22:04:23 PDT 2011
Author: dgregor
Date: Sun Jun 5 00:04:23 2011
New Revision: 132657
URL: http://llvm.org/viewvc/llvm-project?rev=132657&view=rev
Log:
When inferring the result type of a block based on a return statement
with a type-dependent expression, infer the placeholder type
'Context.DependentTy' to indicate that this is just a
placeholder. Fixes PR9982 / <rdar://problem/9486685>.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CodeGenObjCXX/block-in-template-inst.mm
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=132657&r1=132656&r2=132657&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Jun 5 00:04:23 2011
@@ -2082,6 +2082,7 @@
case Decl::FunctionTemplate:
case Decl::TypeAliasTemplate:
case Decl::NamespaceAlias:
+ case Decl::Block:
break;
case Decl::CXXConstructor:
// Skip function templates
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=132657&r1=132656&r2=132657&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Jun 5 00:04:23 2011
@@ -1589,14 +1589,18 @@
if (Result.isInvalid())
return StmtError();
RetValExp = Result.take();
- CurBlock->ReturnType = RetValExp->getType();
- if (BlockDeclRefExpr *CDRE = dyn_cast<BlockDeclRefExpr>(RetValExp)) {
- // We have to remove a 'const' added to copied-in variable which was
- // part of the implementation spec. and not the actual qualifier for
- // the variable.
- if (CDRE->isConstQualAdded())
- CurBlock->ReturnType.removeLocalConst(); // FIXME: local???
- }
+
+ if (!RetValExp->isTypeDependent()) {
+ CurBlock->ReturnType = RetValExp->getType();
+ if (BlockDeclRefExpr *CDRE = dyn_cast<BlockDeclRefExpr>(RetValExp)) {
+ // We have to remove a 'const' added to copied-in variable which was
+ // part of the implementation spec. and not the actual qualifier for
+ // the variable.
+ if (CDRE->isConstQualAdded())
+ CurBlock->ReturnType.removeLocalConst(); // FIXME: local???
+ }
+ } else
+ CurBlock->ReturnType = Context.DependentTy;
} else
CurBlock->ReturnType = Context.VoidTy;
}
@@ -1658,7 +1662,7 @@
// If we need to check for the named return value optimization, save the
// return statement in our scope for later processing.
- if (getLangOptions().CPlusPlus && FnRetType->isRecordType() &&
+ if (getLangOptions().CPlusPlus && FnRetType->isRecordType() &&
!CurContext->isDependentContext())
FunctionScopes.back()->Returns.push_back(Result);
Modified: cfe/trunk/test/CodeGenObjCXX/block-in-template-inst.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/block-in-template-inst.mm?rev=132657&r1=132656&r2=132657&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/block-in-template-inst.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/block-in-template-inst.mm Sun Jun 5 00:04:23 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fblocks -o - -triple x86_64-apple-darwin10 %s
+// RUN: %clang_cc1 -emit-llvm-only -std=c++0x -fblocks -o - -triple x86_64-apple-darwin10 %s
// rdar://9362021
@class DYFuture;
@@ -32,3 +32,40 @@
ResourceManager<AnalyzerBaseObjectTypes> *rm;
^(void) { rm->XXX(); }();
}
+
+namespace PR9982 {
+ template<typename T> struct Curry;
+
+ template<typename R, typename Arg0, typename Arg1, typename Arg2>
+ struct Curry<R (^)(Arg0, Arg1, Arg2)>
+ {
+ typedef R (^FType)(Arg0, Arg1, Arg2);
+
+ Curry(FType _f) : f(_f) {}
+ ~Curry() {;}
+
+ R (^(^operator()(Arg0 a))(Arg1))(Arg2)
+ {
+ auto block = ^(Arg1 b) {
+ auto inner_block = ^(Arg2 c) {
+ return f(a, b, c);
+ };
+ return inner_block;
+ };
+ return block;
+ }
+
+ private:
+ FType f;
+ };
+
+ auto add = ^(int a, int b, int c)
+ {
+ return a + b + c;
+ };
+
+ void curry() {
+ Curry<__decltype(add)> c = Curry<__decltype(add)>(add);
+ auto t = c(1)(10)(100);
+ }
+}
More information about the cfe-commits
mailing list