[cfe-commits] r42936 - in /cfe/trunk: Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Type.h include/clang/Basic/DiagnosticKinds.def test/Sema/invalid-objc-decls-1.m
Fariborz Jahanian
fjahanian at apple.com
Fri Oct 12 15:10:43 PDT 2007
Author: fjahanian
Date: Fri Oct 12 17:10:42 2007
New Revision: 42936
URL: http://llvm.org/viewvc/llvm-project?rev=42936&view=rev
Log:
Check and diagnose that objective-c objects may not be statically allocated.
Added:
cfe/trunk/test/Sema/invalid-objc-decls-1.m
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42936&r1=42935&r2=42936&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct 12 17:10:42 2007
@@ -556,6 +556,11 @@
} 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 @@
}
}
}
+ /// 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.
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42936&r1=42935&r2=42936&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Oct 12 17:10:42 2007
@@ -742,6 +742,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=42936&r1=42935&r2=42936&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Oct 12 17:10:42 2007
@@ -275,6 +275,7 @@
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::isOCUVectorType() const {
return isa<OCUVectorType>(CanonicalType);
}
-
+inline bool Type::isObjcInterfaceType() const {
+ return isa<ObjcInterfaceType>(CanonicalType)
+ || isa<ObjcQualifiedInterfaceType>(CanonicalType);
+}
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=42936&r1=42935&r2=42936&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Oct 12 17:10:42 2007
@@ -452,6 +452,8 @@
"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
Added: cfe/trunk/test/Sema/invalid-objc-decls-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-objc-decls-1.m?rev=42936&view=auto
==============================================================================
--- cfe/trunk/test/Sema/invalid-objc-decls-1.m (added)
+++ cfe/trunk/test/Sema/invalid-objc-decls-1.m Fri Oct 12 17:10:42 2007
@@ -0,0 +1,29 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at 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'}}
+};
+
+ at protocol P1 @end
+
+ at interface INTF
+{
+ Super ivar1; // expected-error{{statically allocated Objective-c object 'ivar1'}}
+}
+ at end
+
+ at interface MyIntf
+{
+ Super<P1> ivar1; // expected-error{{statically allocated Objective-c object 'ivar1'}}
+}
+ at end
+
+Super foo(Super parm1) {
+ Super p1; // expected-error{{statically allocated Objective-c object 'p1'}}
+ return p1;
+}
More information about the cfe-commits
mailing list