[cfe-commits] r152147 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/unknown-anytype-blocks.cpp
Sean Callanan
scallanan at apple.com
Tue Mar 6 13:34:13 PST 2012
Author: spyffe
Date: Tue Mar 6 15:34:12 2012
New Revision: 152147
URL: http://llvm.org/viewvc/llvm-project?rev=152147&view=rev
Log:
Extended the UnknownAnyTy resolver to handle
blocks with unknown return types. This allows
LLDB to call blocks even when their return types
aren't provided in the debug information.
Added:
cfe/trunk/test/SemaCXX/unknown-anytype-blocks.cpp
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=152147&r1=152146&r2=152147&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Mar 6 15:34:12 2012
@@ -10810,20 +10810,44 @@
ExprResult RebuildUnknownAnyExpr::VisitImplicitCastExpr(ImplicitCastExpr *E) {
// The only case we should ever see here is a function-to-pointer decay.
- assert(E->getCastKind() == CK_FunctionToPointerDecay);
- assert(E->getValueKind() == VK_RValue);
- assert(E->getObjectKind() == OK_Ordinary);
-
- E->setType(DestType);
-
- // Rebuild the sub-expression as the pointee (function) type.
- DestType = DestType->castAs<PointerType>()->getPointeeType();
-
- ExprResult Result = Visit(E->getSubExpr());
- if (!Result.isUsable()) return ExprError();
-
- E->setSubExpr(Result.take());
- return S.Owned(E);
+ if (E->getCastKind() == CK_FunctionToPointerDecay)
+ {
+ assert(E->getValueKind() == VK_RValue);
+ assert(E->getObjectKind() == OK_Ordinary);
+
+ E->setType(DestType);
+
+ // Rebuild the sub-expression as the pointee (function) type.
+ DestType = DestType->castAs<PointerType>()->getPointeeType();
+
+ ExprResult Result = Visit(E->getSubExpr());
+ if (!Result.isUsable()) return ExprError();
+
+ E->setSubExpr(Result.take());
+ return S.Owned(E);
+ }
+ else if (E->getCastKind() == CK_LValueToRValue)
+ {
+ assert(E->getValueKind() == VK_RValue);
+ assert(E->getObjectKind() == OK_Ordinary);
+
+ assert(isa<BlockPointerType>(E->getType()));
+
+ E->setType(DestType);
+
+ // The sub-expression has to be a lvalue reference, so rebuild it as such.
+ DestType = S.Context.getLValueReferenceType(DestType);
+
+ ExprResult Result = Visit(E->getSubExpr());
+ if (!Result.isUsable()) return ExprError();
+
+ E->setSubExpr(Result.take());
+ return S.Owned(E);
+ }
+ else
+ {
+ llvm_unreachable("Unhandled cast type!");
+ }
}
ExprResult RebuildUnknownAnyExpr::resolveDecl(Expr *E, ValueDecl *VD) {
Added: cfe/trunk/test/SemaCXX/unknown-anytype-blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unknown-anytype-blocks.cpp?rev=152147&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/unknown-anytype-blocks.cpp (added)
+++ cfe/trunk/test/SemaCXX/unknown-anytype-blocks.cpp Tue Mar 6 15:34:12 2012
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -funknown-anytype -fblocks -fsyntax-only -verify -std=c++11 %s
+
+namespace test1 {
+ __unknown_anytype (^foo)();
+ __unknown_anytype (^bar)();
+ int test() {
+ auto ret1 = (int)foo();
+ auto ret2 = bar(); // expected-error {{'bar' has unknown return type; cast the call to its declared return type}}
+ return ret1;
+ }
+}
More information about the cfe-commits
mailing list