]> granicus.if.org Git - clang/commitdiff
reject sizeof(itf) when itf is a forward declared interface, or when
authorChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 19:55:16 +0000 (19:55 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 19:55:16 +0000 (19:55 +0000)
in non-fragile abi mode.  rdar://6811884

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69701 91177308-0d34-0410-b5e6-96231b3b80d8

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

index acfc006738b49595cb457b8091fad91bea4c76eb..f264de4d0cb4461f8d9eaea87c638e9f7e4cb39c 100644 (file)
@@ -919,6 +919,12 @@ def ext_sizeof_function_type : Extension<
   "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">;
index 788361b59a0b4b75149e62de843ef042f5d85579..b6f1afbe41afbd6c09f0ee3e533351759077aae2 100644 (file)
@@ -1225,7 +1225,22 @@ bool Sema::CheckSizeOfAlignOfOperand(QualType exprType,
       << (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,
index 9ed63a7406ec66500f6da8a6938974dfbad1da8a..3dae7b9017d15de7e5caeeaab1735d27d7061fde 100644 (file)
@@ -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 @@ int g1[ sizeof(I0) == 4 ? 1 : -1];
 
 // 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;