Added a diagnostic for mismatched MS inheritance attributes. Also fixed the incomplete type member pointer size calculation under the MS ABI.

llvm-svn: 163078
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 50d1117..bf1c143 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4149,20 +4149,50 @@
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid";
 }
 
+static bool hasOtherInheritanceAttr(Decl *D, AttributeList::Kind Kind,
+    int& Existing) {
+  if (Kind != AttributeList::AT_SingleInheritance &&
+      D->hasAttr<SingleInheritanceAttr>()) {
+    Existing = 0;
+    return true;
+  }
+  else if (Kind != AttributeList::AT_MultipleInheritance &&
+      D->hasAttr<MultipleInheritanceAttr>()) {
+    Existing = 1;
+    return true;
+  }
+  else if (Kind != AttributeList::AT_VirtualInheritance &&
+      D->hasAttr<VirtualInheritanceAttr>()) {
+    Existing = 2;
+    return true;
+  }
+  return false;
+}
+
 static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (S.LangOpts.MicrosoftExt) {
-    AttributeList::Kind Kind = Attr.getKind();
-    if (Kind == AttributeList::AT_SingleInheritance)
-      D->addAttr(
-          ::new (S.Context) SingleInheritanceAttr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_MultipleInheritance)
-      D->addAttr(
-          ::new (S.Context) MultipleInheritanceAttr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_VirtualInheritance)
-      D->addAttr(
-          ::new (S.Context) VirtualInheritanceAttr(Attr.getRange(), S.Context));
-  } else
+  if (!S.LangOpts.MicrosoftExt) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+    return;
+  }
+
+  AttributeList::Kind Kind = Attr.getKind();
+
+  int Existing;
+  if (hasOtherInheritanceAttr(D->getCanonicalDecl(), Kind, Existing)) {
+      S.Diag(Attr.getLoc(), diag::warn_ms_inheritance_already_declared) << Existing;
+      return;
+  }
+
+  if (Kind == AttributeList::AT_SingleInheritance) {
+    D->addAttr(
+        ::new (S.Context) SingleInheritanceAttr(Attr.getRange(), S.Context));
+  } else if (Kind == AttributeList::AT_MultipleInheritance) {
+    D->addAttr(
+        ::new (S.Context) MultipleInheritanceAttr(Attr.getRange(), S.Context));
+  } else if (Kind == AttributeList::AT_VirtualInheritance) {
+    D->addAttr(
+        ::new (S.Context) VirtualInheritanceAttr(Attr.getRange(), S.Context));
+  }
 }
 
 static void handlePortabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {