From: Daniel Dunbar Date: Fri, 2 Apr 2010 20:10:03 +0000 (+0000) Subject: Sema/Obj-C: Narrow type of ObjCIvarDecl::Create, and check additional invariants... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a06549226f45d5b72169a3d054415616dd1014a2;p=clang Sema/Obj-C: Narrow type of ObjCIvarDecl::Create, and check additional invariants on the provided DeclContext. - Doug, please see the FIXME in DeclObjC.cpp -- I am not sure what the right fix is. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100213 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index a1f565341e..aafbe109f9 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -624,14 +624,14 @@ public: }; private: - ObjCIvarDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, + ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW) : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false), DeclAccess(ac) {} public: - static ObjCIvarDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, - IdentifierInfo *Id, QualType T, + static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC, + SourceLocation L, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW = NULL); diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 75cf1380a1..f7d08e8b77 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -2013,7 +2013,8 @@ Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { if (!BitWidth && D->getBitWidth()) return 0; - ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), DC, + ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), + cast(DC), Loc, Name.getAsIdentifierInfo(), T, TInfo, D->getAccessControl(), BitWidth); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index ab6b9e1f45..63f3e04772 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -561,10 +561,26 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, // ObjCIvarDecl //===----------------------------------------------------------------------===// -ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC, +ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW) { + if (DC) { + // Ivar's can only appear in interfaces, implementations (via synthesized + // properties), and class extensions (via direct declaration, or synthesized + // properties). + // + // FIXME: This should really be asserting this: + // (isa(DC) && + // cast(DC)->IsClassExtension())) + // but unfortunately we sometimes place ivars into non-class extension + // categories on error. This breaks an AST invariant, and should not be + // fixed. + assert((isa(DC) || isa(DC) || + isa(DC)) && + "Invalid ivar decl context!"); + } + return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW); }