]> granicus.if.org Git - clang/commitdiff
Check and diagnose that objective-c objects may not be statically allocated.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Oct 2007 22:10:42 +0000 (22:10 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Oct 2007 22:10:42 +0000 (22:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42936 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/Type.h
include/clang/Basic/DiagnosticKinds.def
test/Sema/invalid-objc-decls-1.m [new file with mode: 0644]

index 9d47375f506541b19b79fcca1a044d92507e9bfd..b66c9f4860d5e89f94c15fe20160839ec7b1aebd 100644 (file)
@@ -556,6 +556,11 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
   } else {
     QualType R = GetTypeForDeclarator(D, S);
     assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
+    if (R.getTypePtr()->isObjcInterfaceType()) {
+      Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object,
+           D.getIdentifier()->getName());
+      InvalidDecl = true;
+    }
 
     VarDecl *NewVD;
     VarDecl::StorageClass SC;
@@ -1680,6 +1685,14 @@ void Sema::ActOnFields(Scope* S,
         }
       }
     }
+    /// A field cannot be an Objective-c object
+    if (FDTy->isObjcInterfaceType()) {
+      Diag(FD->getLocation(), diag::err_statically_allocated_object,
+           FD->getName());
+      FD->setInvalidDecl();
+      EnclosingDecl->setInvalidDecl();
+      continue;
+    }
     // Keep track of the number of named members.
     if (IdentifierInfo *II = FD->getIdentifier()) {
       // Detect duplicate member names.
index b88c381faa0b21298a15082c3f3667bb0e3dacc7..75d938806b0068e9faf478a9935977559b88f772 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index 5018ca0c1df8987d0790d2ae322b102c9d323734..061f34c054c217bf9ce8f0ecf08d4cf3c1f00cf8 100644 (file)
@@ -275,6 +275,7 @@ public:
   bool isUnionType() const;  
   bool isVectorType() const; // GCC vector type.
   bool isOCUVectorType() const; // OCU vector type.
+  bool isObjcInterfaceType() const; // includes conforming protocol type
   
   // Type Checking Functions: Check to see if this type is structurally the
   // specified type, ignoring typedefs, and return a pointer to the best type
@@ -933,7 +934,10 @@ inline bool Type::isVectorType() const {
 inline bool Type::isOCUVectorType() const {
   return isa<OCUVectorType>(CanonicalType);
 }
-
+inline bool Type::isObjcInterfaceType() const {
+  return isa<ObjcInterfaceType>(CanonicalType)
+           || isa<ObjcQualifiedInterfaceType>(CanonicalType);
+}
 }  // end namespace clang
 
 #endif
index dec9343cbbd97eee51c840ccd2cc38998b313f55..2a8900c02578199f0d51aeea2dcf8b4a429a2bf6 100644 (file)
@@ -452,6 +452,8 @@ DIAG(warn_previous_declaration, WARNING,
      "previous declaration is here")
 DIAG(err_conflicting_aliasing_type, ERROR,
      "conflicting types for alias %0'")
+DIAG(err_statically_allocated_object, ERROR,
+     "statically allocated Objective-c object '%0'")
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis
diff --git a/test/Sema/invalid-objc-decls-1.m b/test/Sema/invalid-objc-decls-1.m
new file mode 100644 (file)
index 0000000..9d88fdc
--- /dev/null
@@ -0,0 +1,29 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface Super @end
+Super s1; // expected-error{{statically allocated Objective-c object 's1'}}
+
+extern Super e1; // expected-error{{statically allocated Objective-c object 'e1'}}
+
+struct S {
+  Super s1; // expected-error{{statically allocated Objective-c object 's1'}}
+};
+
+@protocol P1 @end
+
+@interface INTF
+{
+  Super ivar1; // expected-error{{statically allocated Objective-c object 'ivar1'}}
+}
+@end
+
+@interface MyIntf
+{
+  Super<P1> ivar1; // expected-error{{statically allocated Objective-c object 'ivar1'}}
+}
+@end
+
+Super foo(Super parm1) {
+       Super p1; // expected-error{{statically allocated Objective-c object 'p1'}}
+       return p1;
+}