[cfe-commits] r69701 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/sizeof-interface.m

Chris Lattner sabre at nondot.org
Tue Apr 21 12:55:17 PDT 2009


Author: lattner
Date: Tue Apr 21 14:55:16 2009
New Revision: 69701

URL: http://llvm.org/viewvc/llvm-project?rev=69701&view=rev
Log:
reject sizeof(itf) when itf is a forward declared interface, or when
in non-fragile abi mode.  rdar://6811884

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/sizeof-interface.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69701&r1=69700&r2=69701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 21 14:55:16 2009
@@ -919,6 +919,12 @@
   "invalid application of 'sizeof' to a function type">;
 def ext_sizeof_void_type : Extension<
   "invalid application of '%0' to a void type">;
+def err_sizeof_forward_interface : Error<
+  "invalid application of '%select{alignof|sizeof}1' to a forward declared"
+  " interface %0">;
+def err_sizeof_nonfragile_interface : Error<
+  "invalid application of '%select{alignof|sizeof}1' to interface %0 in "
+  "non-fragile ABI">;
 // FIXME: merge with %select
 def err_sizeof_incomplete_type : Error<
   "invalid application of 'sizeof' to an incomplete type %0">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=69701&r1=69700&r2=69701&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Apr 21 14:55:16 2009
@@ -1225,7 +1225,22 @@
       << (isSizeof ? "sizeof" : "__alignof") << ExprRange;
     return false;
   }
+  
+  // sizeof(interface) and sizeof(interface<proto>)
+  if (const ObjCInterfaceType *IIT = exprType->getAsObjCInterfaceType()) {
+    if (IIT->getDecl()->isForwardDecl()) {
+      Diag(OpLoc, diag::err_sizeof_forward_interface)
+        << IIT->getDecl()->getDeclName() << isSizeof;
+      return true;
+    }
 
+    if (LangOpts.ObjCNonFragileABI) {
+      Diag(OpLoc, diag::err_sizeof_nonfragile_interface)
+        << IIT->getDecl()->getDeclName() << isSizeof;
+      return true;
+    }
+  }
+    
   return RequireCompleteType(OpLoc, exprType,
                                 isSizeof ? diag::err_sizeof_incomplete_type : 
                                            diag::err_alignof_incomplete_type,

Modified: cfe/trunk/test/SemaObjC/sizeof-interface.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/sizeof-interface.m?rev=69701&r1=69700&r2=69701&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/sizeof-interface.m (original)
+++ cfe/trunk/test/SemaObjC/sizeof-interface.m Tue Apr 21 14:55:16 2009
@@ -1,8 +1,9 @@
-// RUN: clang-cc -triple x86_64-apple-darwin9 -fsyntax-only %s
+// RUN: clang-cc -triple x86_64-apple-darwin9 -verify -fsyntax-only %s
 
 @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 ...}}
+
+// rdar://6811884
+int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to a forward declared interface 'I0'}}
 
 @interface I0 {
   char x[4];
@@ -12,7 +13,8 @@
 @end
 
 // size == 4
-int g1[ sizeof(I0) == 4 ? 1 : -1];
+int g1[ sizeof(I0)     // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
+       == 4 ? 1 : -1];
 
 @implementation I0
 @synthesize p0 = _p0;
@@ -20,7 +22,8 @@
 
 // size == 4 (we do not include extended properties in the
 // sizeof).
-int g2[ sizeof(I0) == 4 ? 1 : -1];
+int g2[ sizeof(I0)   // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
+       == 4 ? 1 : -1];
 
 @interface I1
 @property int p0;





More information about the cfe-commits mailing list