erichkeane updated this revision to Diff 115153.
erichkeane retitled this revision from "Interface class with uuid base record"
to "Fix the __interface inheritence rules to work better with IUnknown and
IDispatch".
erichkeane edited the summary of this revision.
erichkeane added a comment.
Herald added a subscriber: eraman.
Based off of what I discovered previously, this is my first run at a solution
to this problem. @zahiraam (and others), if you can see if I missed anything in
this patch, it would be appreciated. I think this is a good place to start
further discussion than text conversation.
https://reviews.llvm.org/D37308
Files:
include/clang/AST/DeclCXX.h
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/ms-iunknown-inline-def.cpp
test/SemaCXX/ms-iunknown-outofline-def.cpp
test/SemaCXX/ms-iunknown.cpp
Index: test/SemaCXX/ms-iunknown.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/ms-iunknown.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
+
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {
+ void foo();
+};
+struct IPropertyPageBase : public IUnknown {};
+struct IPropertyPage : public IPropertyPageBase {};
+__interface ISfFileIOPropertyPage : public IPropertyPage {};
+
+
+namespace NS {
+ struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {};
+ // expected-error@+1 {{interface type cannot inherit from}}
+ __interface IPropertyPageBase : public IUnknown {};
+}
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface IPropertyPageBase2 : public NS::IUnknown {};
+
+__interface temp_iface {};
+struct bad_base : temp_iface {};
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface cant_inherit: public bad_base{};
+
+struct fine_base : temp_iface, IUnknown {};
+__interface can_inherit: public fine_base{};
+
+struct PageBase : public IUnknown {};
+struct Page3 : public PageBase {};
+struct Page4 : public PageBase {};
+__interface PropertyPage : public Page4 {};
+
+struct Page5 : public Page3, Page4{};
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface PropertyPage2 : public Page5 {};
+
+__interface IF1 {};
+__interface PP : IUnknown, IF1{};
+__interface PP2 : PP, Page3, Page4{};
Index: test/SemaCXX/ms-iunknown-outofline-def.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/ms-iunknown-outofline-def.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
+
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {
+ void foo();
+};
+
+__interface NoError : public IUnknown {};
+void IUnknown::foo() {}
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {};
Index: test/SemaCXX/ms-iunknown-inline-def.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/ms-iunknown-inline-def.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
+
+struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {
+ void foo() {}
+};
+
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {};
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -2388,7 +2388,7 @@
if (const RecordType *Record = NewBaseType->getAs<RecordType>()) {
const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
if (Class->isInterface() &&
- (!RD->isInterface() ||
+ (!RD->isInterfaceLike() ||
KnownBase->getAccessSpecifier() != AS_public)) {
// The Microsoft extension __interface does not permit bases that
// are not themselves public interfaces.
Index: lib/AST/DeclCXX.cpp
===================================================================
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -1470,6 +1470,61 @@
return false;
}
+bool CXXRecordDecl::isInterfaceLike() const {
+ // All __interfaces are inheritently interface like.
+ if (isInterface())
+ return true;
+
+ // No interface-like types can have a user declared constructor, destructor,
+ // friends, VBases, conersion functions, or fields. Additionally, lambdas
+ // cannot be interface types.
+ if (isLambda() || hasUserDeclaredConstructor() ||
+ hasUserDeclaredDestructor() || !field_empty() || hasFriends() ||
+ getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
+ return false;
+
+ // No interface-like type can have a method with a definition.
+ for (const auto *const Method : methods())
+ if (Method->isDefined())
+ return false;
+
+ // Check "Special" types.
+ const auto *Uuid = getAttr<UuidAttr>();
+ if (Uuid && isStruct() && getDeclContext()->isTranslationUnit() &&
+ ((getName() == "IUnknown" &&
+ Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
+ (getName() == "IDispatch" &&
+ Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) {
+ if (getNumBases() > 0)
+ return false;
+ return true;
+ }
+
+ // FIXME: Any access specifiers is supposed to make this no longer interface
+ // like.
+
+ // If this isn't a 'special' type, it must have exclusively interface &
+ // interface-like bases. It must have a single interface-like base.
+ int NumInterfaceLikeBases = 0;
+ if (getNumBases() == 0)
+ return false;
+
+ for (const auto BS : bases()) {
+ if (BS.isVirtual() || BS.getAccessSpecifier() != AS_public)
+ return false;
+ const auto *Base = BS.getType()->getAsCXXRecordDecl();
+ if (Base->isInterface())
+ continue;
+ if (Base->isInterfaceLike()) {
+ ++NumInterfaceLikeBases;
+ } else {
+ return false;
+ }
+ }
+
+ return NumInterfaceLikeBases == 1;
+}
+
void CXXRecordDecl::completeDefinition() {
completeDefinition(nullptr);
}
Index: include/clang/AST/DeclCXX.h
===================================================================
--- include/clang/AST/DeclCXX.h
+++ include/clang/AST/DeclCXX.h
@@ -1831,6 +1831,10 @@
return getLambdaData().MethodTyInfo;
}
+ // \brief Determine whether this type is an Interface Like type for
+ // __interface inheritence purposes.
+ bool isInterfaceLike() const;
+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) {
return K >= firstCXXRecord && K <= lastCXXRecord;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits