[cfe-commits] r106130 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjCXX/instantiate-method-return.mm

Douglas Gregor dgregor at apple.com
Wed Jun 16 11:59:41 PDT 2010


On Jun 16, 2010, at 11:56 AM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Wed Jun 16 13:56:04 2010
> New Revision: 106130
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=106130&view=rev
> Log:
> Make sure result type of objc++ message expression is
> complete before attempting to bind it to a temporary.
> Fixes PR7386.
> 
> Added:
>    cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaExprCXX.cpp
>    cfe/trunk/lib/Sema/SemaExprObjC.cpp
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=106130&r1=106129&r2=106130&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 16 13:56:04 2010
> @@ -1888,6 +1888,8 @@
>   "'%0' declared as array of functions of type %1">;
> def err_illegal_decl_array_incomplete_type : Error<
>   "array has incomplete element type %0">;
> +def err_illegal_message_expr_incomplete_type : Error<
> +  "objective-c message has incomplete result type %0">;
> def err_illegal_decl_array_of_references : Error<
>   "'%0' declared as array of references of type %1">;
> def err_array_star_outside_prototype : Error<
> 
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=106130&r1=106129&r2=106130&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jun 16 13:56:04 2010
> @@ -17,6 +17,7 @@
> #include "clang/AST/ASTContext.h"
> #include "clang/AST/CXXInheritance.h"
> #include "clang/AST/ExprCXX.h"
> +#include "clang/AST/ExprObjC.h"
> #include "clang/AST/TypeLoc.h"
> #include "clang/Basic/PartialDiagnostic.h"
> #include "clang/Basic/TargetInfo.h"
> @@ -2605,6 +2606,16 @@
>     if (FTy->getResultType()->isReferenceType())
>       return Owned(E);
>   }
> +  else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) {
> +    QualType Ty = ME->getType();
> +    if (const PointerType *PT = Ty->getAs<PointerType>())
> +      Ty = PT->getPointeeType();
> +    else if (const BlockPointerType *BPT = Ty->getAs<BlockPointerType>())
> +      Ty = BPT->getPointeeType();
> +    if (Ty->isReferenceType())
> +      return Owned(E);    
> +  }
> +
> 
>   // That should be enough to guarantee that this type is complete.
>   // If it has a trivial destructor, we can avoid the extra copy.
> 
> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=106130&r1=106129&r2=106130&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Jun 16 13:56:04 2010
> @@ -1018,6 +1018,11 @@
>   else
>     Result = ObjCMessageExpr::Create(Context, ReturnType, LBracLoc, Receiver, 
>                                      Sel, Method, Args, NumArgs, RBracLoc);
> +  if (Context.getLangOptions().CPlusPlus && !ReturnType->isVoidType()) {
> +    if (RequireCompleteType(LBracLoc, ReturnType, 
> +                      diag::err_illegal_message_expr_incomplete_type))
> +      return ExprError();
> +    }

Shouldn't this same restriction also apply in C?

Also, how about moving the complete-type check before we build the ObjCMessageExpr node?

	- Doug





More information about the cfe-commits mailing list