[cfe-commits] r152147 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/unknown-anytype-blocks.cpp

Argyrios Kyrtzidis kyrtzidis at apple.com
Tue Mar 6 15:12:38 PST 2012


On Mar 6, 2012, at 1:34 PM, Sean Callanan wrote:

> 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.

Hi Sean,

LLVM conventions dictate the '{' to be on the same line as 'if' or 'else', and 'else' to be on same line as '}'.

-Argyrios

> 
> 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;
> +  }
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list