[PATCH] D46664: Fix null MSInheritanceAttr deref in CXXRecordDecl::getMSInheritanceModel()

Andrew Rogers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 9 15:31:31 PDT 2018


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".
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46664.146016.patch
Type: text/x-patch
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180509/0883bbc7/attachment.bin>


More information about the cfe-commits mailing list