r200959 - MS ABI: Don't be so hasty to judge an inheritance model

David Majnemer david.majnemer at gmail.com
Thu Feb 6 16:43:07 PST 2014


Author: majnemer
Date: Thu Feb  6 18:43:07 2014
New Revision: 200959

URL: http://llvm.org/viewvc/llvm-project?rev=200959&view=rev
Log:
MS ABI: Don't be so hasty to judge an inheritance model

If we are in the middle of defining the class, don't attempt to
validate previously annotated declarations.  We may not have seen base
specifiers or virtual method declarations yet.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaCXX/member-pointer-ms.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=200959&r1=200958&r2=200959&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Feb  6 18:43:07 2014
@@ -12150,7 +12150,7 @@ void Sema::ActOnFields(Scope *S, SourceL
     if (Record->hasAttrs()) {
       CheckAlignasUnderalignment(Record);
 
-      if (MSInheritanceAttr *IA = Record->getAttr<MSInheritanceAttr>())
+      if (const MSInheritanceAttr *IA = Record->getAttr<MSInheritanceAttr>())
         checkMSInheritanceAttrOnDefinition(cast<CXXRecordDecl>(Record),
                                            IA->getRange(),
                                            IA->getSemanticSpelling());

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=200959&r1=200958&r2=200959&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb  6 18:43:07 2014
@@ -2877,16 +2877,23 @@ bool Sema::checkMSInheritanceAttrOnDefin
     MSInheritanceAttr::Spelling SemanticSpelling) {
   assert(RD->hasDefinition() && "RD has no definition!");
 
-  if (SemanticSpelling != MSInheritanceAttr::Keyword_unspecified_inheritance &&
-      RD->calculateInheritanceModel() != SemanticSpelling) {
-    Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance)
-        << 0 /*definition*/;
-    Diag(RD->getDefinition()->getLocation(), diag::note_defined_here)
-        << RD->getNameAsString();
-    return true;
-  }
+  // We may not have seen base specifiers or any virtual methods yet.  We will
+  // have to wait until the record is defined to catch any mismatches.
+  if (!RD->getDefinition()->isCompleteDefinition())
+    return false;
 
-  return false;
+  // The unspecified model never matches what a definition could need.
+  if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance)
+    return false;
+
+  if (RD->calculateInheritanceModel() == SemanticSpelling)
+    return false;
+
+  Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance)
+      << 0 /*definition*/;
+  Diag(RD->getDefinition()->getLocation(), diag::note_defined_here)
+      << RD->getNameAsString();
+  return true;
 }
 
 /// handleModeAttr - This attribute modifies the width of a decl with primitive

Modified: cfe/trunk/test/SemaCXX/member-pointer-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer-ms.cpp?rev=200959&r1=200958&r2=200959&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer-ms.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-pointer-ms.cpp Thu Feb  6 18:43:07 2014
@@ -198,4 +198,7 @@ struct __multiple_inheritance B; // expe
 
 struct __multiple_inheritance C {}; // expected-error{{inheritance model does not match definition}}
  // expected-note at -1 {{C defined here}}
+
+struct __virtual_inheritance D;
+struct D : virtual B {};
 }





More information about the cfe-commits mailing list