Already done. :)<div><br></div><div><rdar://problem/6811884> [sema] reject sizeof applied to incomplete interface type</div><div><br></div><div> - Daniel<br><br><div class="gmail_quote">On Tue, Apr 21, 2009 at 9:31 AM, Fariborz Jahanian <span dir="ltr"><<a href="mailto:fjahanian@apple.com">fjahanian@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
On Apr 21, 2009, at 8:48 AM, Daniel Dunbar wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: ddunbar<br>
Date: Tue Apr 21 10:48:54 2009<br>
New Revision: 69675<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=69675&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=69675&view=rev</a><br>
Log:<br>
Use an ASTRecordLayout to compute the sizeof an interface, not<br>
addRecordToClass.<br>
- Among other things, this fixes a crash when applying sizeof to an<br>
  interface with synthesized ivars, although things still aren't<br>
</blockquote>
<br></div>
sizeof, as well as @defs is illegal in NonFrigile ABI, Please file a radar<br>
to catch them.<br><font color="#888888">
<br>
- Fariborz</font><div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
  "correct" here.<br>
<br>
Added:<br>
   cfe/trunk/test/SemaObjC/sizeof-interface.m<br>
Modified:<br>
   cfe/trunk/lib/AST/ExprConstant.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=69675&r1=69674&r2=69675&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=69675&r1=69674&r2=69675&view=diff</a><br>

<br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Apr 21 10:48:54 2009<br>
@@ -1079,18 +1079,18 @@<br>
  if (!SrcTy->isConstantSizeType())<br>
    return false;<br>
<br>
+  unsigned BitWidth = 0;<br>
  if (SrcTy->isObjCInterfaceType()) {<br>
    // Slightly unusual case: the size of an ObjC interface type is the<br>
-    // size of the class.  This code intentionally falls through to the normal<br>
-    // case.<br>
+    // size of the class.<br>
    ObjCInterfaceDecl *OI = SrcTy->getAsObjCInterfaceType()->getDecl();<br>
-    RecordDecl *RD = const_cast<RecordDecl*>(Info.Ctx.addRecordToClass(OI));<br>
-    SrcTy = Info.Ctx.getTagDeclType(static_cast<TagDecl*>(RD));<br>
-  }<br>
+    const ASTRecordLayout &Layout = Info.Ctx.getASTObjCInterfaceLayout(OI);<br>
+    BitWidth = Layout.getSize();<br>
+  } else<br>
+    BitWidth = Info.Ctx.getTypeSize(SrcTy);<br>
<br>
  // Get information about the size.<br>
-  unsigned CharSize = Info.Ctx.Target.getCharWidth();<br>
-  return Success(Info.Ctx.getTypeSize(SrcTy) / CharSize, E);<br>
+  return Success(BitWidth / Info.Ctx.Target.getCharWidth(), E);<br>
}<br>
<br>
bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {<br>
<br>
Added: cfe/trunk/test/SemaObjC/sizeof-interface.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/sizeof-interface.m?rev=69675&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/sizeof-interface.m?rev=69675&view=auto</a><br>

<br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjC/sizeof-interface.m (added)<br>
+++ cfe/trunk/test/SemaObjC/sizeof-interface.m Tue Apr 21 10:48:54 2009<br>
@@ -0,0 +1,35 @@<br>
+// RUN: clang-cc -triple x86_64-apple-darwin9 -fsyntax-only %t<br>
+<br>
+@class I0;<br>
+// FIXME: Reject sizeof on incomplete interface; this breaks the test!<br>
+//int g0 = sizeof(I0); // exxpected-error{{invalid application of 'sizeof' to an incomplete type ...}}<br>
+<br>
+@interface I0 {<br>
+  char x[4];<br>
+}<br>
+<br>
+@property int p0;<br>
+@end<br>
+<br>
+// size == 4<br>
+int g1[ sizeof(I0) == 4 ? 1 : -1];<br>
+<br>
+@implementation I0<br>
+@synthesize p0 = _p0;<br>
+@end<br>
+<br>
+// size == 4 (we do not include extended properties in the<br>
+// sizeof).<br>
+int g2[ sizeof(I0) == 4 ? 1 : -1];<br>
+<br>
+@interface I1<br>
+@property int p0;<br>
+@end<br>
+<br>
+@implementation I1<br>
+@synthesize p0 = _p0;<br>
+@end<br>
+<br>
+// FIXME: This is currently broken due to the way the record layout we<br>
+// create is tied to whether we have seen synthesized properties. Ugh.<br>
+// int g3[ sizeof(I1) == 0 ? 1 : -1];<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>