[cfe-commits] r67450 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/Basic/DiagnosticSemaKinds.def include/clang/Basic/DiagnosticSemaKinds.td lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclObjC.cpp test/CodeGenObjC/interface-tu-variable.m test/SemaObjC/interface-tu-variable.m
Fariborz Jahanian
fjahanian at apple.com
Sat Mar 21 11:06:45 PDT 2009
Author: fjahanian
Date: Sat Mar 21 13:06:45 2009
New Revision: 67450
URL: http://llvm.org/viewvc/llvm-project?rev=67450&view=rev
Log:
Issue error if variables are defined inside an objc class,
category or protocol.
Added:
cfe/trunk/test/SemaObjC/interface-tu-variable.m
Removed:
cfe/trunk/test/CodeGenObjC/interface-tu-variable.m
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=67450&r1=67449&r2=67450&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sat Mar 21 13:06:45 2009
@@ -246,11 +246,6 @@
///
class ObjCContainerDecl : public NamedDecl, public DeclContext {
SourceLocation AtEndLoc; // marks the end of the method container.
- // FIXME. In the long term, all TU variables declared in class scope belong
- // to class's decl context. This waits till we can establish class's
- // context before processing all decls in the class.
- /// Instance variables in the interface.
- ObjCList<VarDecl> TUVars;
public:
ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
@@ -303,15 +298,7 @@
ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const {
return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel);
}
-
- typedef ObjCList<VarDecl>::iterator tuvar_iterator;
- tuvar_iterator tuvar_begin() const { return TUVars.begin(); }
- tuvar_iterator tuvar_end() const { return TUVars.end(); }
- unsigned tuvar_size() const { return TUVars.size(); }
- void setTUVarList(VarDecl * const *List, unsigned Num, ASTContext &C) {
- TUVars.set(List, Num, C);
- }
-
+
ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
// Marks the end of the container.
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=67450&r1=67449&r2=67450&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Sat Mar 21 13:06:45 2009
@@ -1025,6 +1025,8 @@
"illegal qualifiers on @catch parameter")
DIAG(err_illegal_super_cast, ERROR,
"cannot cast 'super' (it isn't an expression)")
+DIAG(err_objc_var_decl_inclass, ERROR,
+ "cannot declare variable inside a class, protocol or category %0")
// C++ casts
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67450&r1=67449&r2=67450&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Mar 21 13:06:45 2009
@@ -161,6 +161,8 @@
def note_declared_at : Note<"declared at">;
def err_setter_type_void : Error<"type of setter must be void">;
def err_duplicate_method_decl : Error<"duplicate declaration of method %0">;
+def err_objc_var_decl_inclass :
+ Error<"cannot declare variable inside a class, protocol or category %0">;
def error_missing_method_context : Error<
"missing context for method declaration">;
def err_objc_property_attr_mutually_exclusive : Error<
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67450&r1=67449&r2=67450&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Mar 21 13:06:45 2009
@@ -1270,21 +1270,13 @@
// Forward declarations, no (immediate) code generation.
case Decl::ObjCClass:
case Decl::ObjCForwardProtocol:
+ case Decl::ObjCCategory:
+ case Decl::ObjCInterface:
break;
case Decl::ObjCProtocol:
- case Decl::ObjCCategory:
- case Decl::ObjCInterface: {
- ObjCContainerDecl *OCD = cast<ObjCContainerDecl>(D);
- for (ObjCContainerDecl::tuvar_iterator i = OCD->tuvar_begin(),
- e = OCD->tuvar_end(); i != e; ++i) {
- VarDecl *VD = *i;
- EmitGlobal(VD);
- }
- if (D->getKind() == Decl::ObjCProtocol)
- Runtime->GenerateProtocol(cast<ObjCProtocolDecl>(D));
+ Runtime->GenerateProtocol(cast<ObjCProtocolDecl>(D));
break;
- }
case Decl::ObjCCategoryImpl:
// Categories have properties but don't support synthesize so we
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=67450&r1=67449&r2=67450&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Mar 21 13:06:45 2009
@@ -1339,14 +1339,16 @@
}
}
}
- llvm::SmallVector<VarDecl*, 8> allTUVariables;
- for (unsigned i = 0; i < tuvNum; i++) {
- if (VarDecl *VD = dyn_cast<VarDecl>((Decl*)allTUVars[i]))
- allTUVariables.push_back(VD);
- }
- if (!allTUVariables.empty() && isInterfaceDeclKind) {
- ObjCContainerDecl *OCD = dyn_cast<ObjCContainerDecl>(ClassDecl);
- OCD->setTUVarList(&allTUVariables[0], allTUVariables.size(), Context);
+ if (isInterfaceDeclKind)
+ for (unsigned i = 0; i < tuvNum; i++) {
+ if (VarDecl *VDecl = dyn_cast<VarDecl>((Decl*)allTUVars[i])) {
+ if (VDecl->getStorageClass() != VarDecl::Extern &&
+ VDecl->getStorageClass() != VarDecl::PrivateExtern) {
+ NamedDecl *ClassNameDecl = dyn_cast<NamedDecl>(ClassDecl);
+ Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass)
+ << ClassNameDecl->getIdentifier();
+ }
+ }
}
}
Removed: cfe/trunk/test/CodeGenObjC/interface-tu-variable.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/interface-tu-variable.m?rev=67449&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/interface-tu-variable.m (original)
+++ cfe/trunk/test/CodeGenObjC/interface-tu-variable.m (removed)
@@ -1,24 +0,0 @@
-// RUN: clang -fnext-runtime -emit-llvm -o %t %s
-// RUN: grep 'two = global' %t &&
-// RUN: grep 'ddd = common' %t &&
-// RUN: grep 'III = common' %t
-
- at interface XX
-int x;
-int one=1;
-int two = 2;
- at end
-
- at protocol PPP
-int ddd;
- at end
-
- at interface XX(CAT)
- char * III;
- at end
-
-
-int main( int argc, const char *argv[] ) {
- return x+one+two;
-}
-
Added: cfe/trunk/test/SemaObjC/interface-tu-variable.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/interface-tu-variable.m?rev=67450&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/interface-tu-variable.m (added)
+++ cfe/trunk/test/SemaObjC/interface-tu-variable.m Sat Mar 21 13:06:45 2009
@@ -0,0 +1,21 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface XX
+int x; // expected-error {{cannot declare variable inside a class, protocol or category}}
+int one=1; // expected-error {{cannot declare variable inside a class, protocol or category}}
+ at end
+
+ at protocol PPP
+int ddd; // expected-error {{cannot declare variable inside a class, protocol or category}}
+ at end
+
+ at interface XX(CAT)
+ char * III; // expected-error {{cannot declare variable inside a class, protocol or category}}
+ extern int OK;
+ at end
+
+
+int main( int argc, const char *argv[] ) {
+ return x+one;
+}
+
More information about the cfe-commits
mailing list