adr26 created this revision. adr26 added a reviewer: rnk. adr26 added a project: clang. Herald added a subscriber: cfe-commits.
Ensure latest MPT decl has a MSInheritanceAttr when instantiating templates, to avoid null MSInheritanceAttr deref in CXXRecordDecl::getMSInheritanceModel(). See PR#37399 for repo / details. Repository: rC Clang https://reviews.llvm.org/D46664 Files: include/clang/Sema/Sema.h lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp Index: lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1551,6 +1551,8 @@ LocalInstantiations.perform(); } + SemaRef.CheckCXXRecordDecl(Record, PrevDecl); + SemaRef.DiagnoseUnusedNestedTypedefs(Record); return Record; Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -7076,6 +7076,21 @@ << TemplateParams->getSourceRange(); } +void Sema::CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev) +{ + if (Prev && Prev->hasAttr<MSInheritanceAttr>()) { + MSInheritanceAttr::Spelling IM = Prev->getMSInheritanceModel(); + Record->addAttr(MSInheritanceAttr::CreateImplicit( + getASTContext(), IM, + /*BestCase=*/MSPointerToMemberRepresentationMethod == + LangOptions::PPTMK_BestCase, + ImplicitMSInheritanceAttrLoc.isValid() + ? ImplicitMSInheritanceAttrLoc + : Record->getSourceRange())); + Consumer.AssignInheritanceModel(Record); + } +} + /// Determine what kind of template specialization the given declaration /// is. static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D) { Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -6470,6 +6470,8 @@ bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); + void CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev); + /// Called when the parser has parsed a C++ typename /// specifier, e.g., "typename T::type". ///
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1551,6 +1551,8 @@ LocalInstantiations.perform(); } + SemaRef.CheckCXXRecordDecl(Record, PrevDecl); + SemaRef.DiagnoseUnusedNestedTypedefs(Record); return Record; Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -7076,6 +7076,21 @@ << TemplateParams->getSourceRange(); } +void Sema::CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev) +{ + if (Prev && Prev->hasAttr<MSInheritanceAttr>()) { + MSInheritanceAttr::Spelling IM = Prev->getMSInheritanceModel(); + Record->addAttr(MSInheritanceAttr::CreateImplicit( + getASTContext(), IM, + /*BestCase=*/MSPointerToMemberRepresentationMethod == + LangOptions::PPTMK_BestCase, + ImplicitMSInheritanceAttrLoc.isValid() + ? ImplicitMSInheritanceAttrLoc + : Record->getSourceRange())); + Consumer.AssignInheritanceModel(Record); + } +} + /// Determine what kind of template specialization the given declaration /// is. static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D) { Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -6470,6 +6470,8 @@ bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); + void CheckCXXRecordDecl(CXXRecordDecl *Record, CXXRecordDecl *Prev); + /// Called when the parser has parsed a C++ typename /// specifier, e.g., "typename T::type". ///
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits