[cfe-commits] r69675 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaObjC/sizeof-interface.m

Fariborz Jahanian fjahanian at apple.com
Tue Apr 21 09:31:12 PDT 2009


On Apr 21, 2009, at 8:48 AM, Daniel Dunbar wrote:

> Author: ddunbar
> Date: Tue Apr 21 10:48:54 2009
> New Revision: 69675
>
> URL: http://llvm.org/viewvc/llvm-project?rev=69675&view=rev
> Log:
> Use an ASTRecordLayout to compute the sizeof an interface, not
> addRecordToClass.
> - Among other things, this fixes a crash when applying sizeof to an
>   interface with synthesized ivars, although things still aren't

sizeof, as well as @defs is illegal in NonFrigile ABI, Please file a  
radar
to catch them.

- Fariborz

>
>   "correct" here.
>
> Added:
>    cfe/trunk/test/SemaObjC/sizeof-interface.m
> Modified:
>    cfe/trunk/lib/AST/ExprConstant.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=69675&r1=69674&r2=69675&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Apr 21 10:48:54 2009
> @@ -1079,18 +1079,18 @@
>   if (!SrcTy->isConstantSizeType())
>     return false;
>
> +  unsigned BitWidth = 0;
>   if (SrcTy->isObjCInterfaceType()) {
>     // Slightly unusual case: the size of an ObjC interface type is  
> the
> -    // size of the class.  This code intentionally falls through to  
> the normal
> -    // case.
> +    // size of the class.
>     ObjCInterfaceDecl *OI = SrcTy->getAsObjCInterfaceType()- 
> >getDecl();
> -    RecordDecl *RD =  
> const_cast<RecordDecl*>(Info.Ctx.addRecordToClass(OI));
> -    SrcTy = Info.Ctx.getTagDeclType(static_cast<TagDecl*>(RD));
> -  }
> +    const ASTRecordLayout &Layout =  
> Info.Ctx.getASTObjCInterfaceLayout(OI);
> +    BitWidth = Layout.getSize();
> +  } else
> +    BitWidth = Info.Ctx.getTypeSize(SrcTy);
>
>   // Get information about the size.
> -  unsigned CharSize = Info.Ctx.Target.getCharWidth();
> -  return Success(Info.Ctx.getTypeSize(SrcTy) / CharSize, E);
> +  return Success(BitWidth / Info.Ctx.Target.getCharWidth(), E);
> }
>
> bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
>
> Added: cfe/trunk/test/SemaObjC/sizeof-interface.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/sizeof-interface.m?rev=69675&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/SemaObjC/sizeof-interface.m (added)
> +++ cfe/trunk/test/SemaObjC/sizeof-interface.m Tue Apr 21 10:48:54  
> 2009
> @@ -0,0 +1,35 @@
> +// RUN: clang-cc -triple x86_64-apple-darwin9 -fsyntax-only %t
> +
> + at class I0;
> +// FIXME: Reject sizeof on incomplete interface; this breaks the  
> test!
> +//int g0 = sizeof(I0); // exxpected-error{{invalid application of  
> 'sizeof' to an incomplete type ...}}
> +
> + at interface I0 {
> +  char x[4];
> +}
> +
> + at property int p0;
> + at end
> +
> +// size == 4
> +int g1[ sizeof(I0) == 4 ? 1 : -1];
> +
> + at implementation I0
> + at synthesize p0 = _p0;
> + at end
> +
> +// size == 4 (we do not include extended properties in the
> +// sizeof).
> +int g2[ sizeof(I0) == 4 ? 1 : -1];
> +
> + at interface I1
> + at property int p0;
> + at end
> +
> + at implementation I1
> + at synthesize p0 = _p0;
> + at end
> +
> +// FIXME: This is currently broken due to the way the record layout  
> we
> +// create is tied to whether we have seen synthesized properties.  
> Ugh.
> +// int g3[ sizeof(I1) == 0 ? 1 : -1];
>
>
> _______________________________________________
> 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