From 4a9ca998d3c0561630965a6ebaa2b15cd9238351 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 13 Apr 2018 22:34:43 +0000 Subject: [PATCH] [ODRHash] Support pointer and reference types. Recommit r328404 which was reverted in rL328404. r329869 fixed the issue that caused the revert. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330074 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ODRHash.cpp | 18 ++++++ test/Modules/odr_hash.cpp | 121 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/lib/AST/ODRHash.cpp b/lib/AST/ODRHash.cpp index 0ee30fbd9b..364fd04b83 100644 --- a/lib/AST/ODRHash.cpp +++ b/lib/AST/ODRHash.cpp @@ -642,6 +642,24 @@ public: VisitFunctionType(T); } + void VisitPointerType(const PointerType *T) { + AddQualType(T->getPointeeType()); + VisitType(T); + } + + void VisitReferenceType(const ReferenceType *T) { + AddQualType(T->getPointeeTypeAsWritten()); + VisitType(T); + } + + void VisitLValueReferenceType(const LValueReferenceType *T) { + VisitReferenceType(T); + } + + void VisitRValueReferenceType(const RValueReferenceType *T) { + VisitReferenceType(T); + } + void VisitTypedefType(const TypedefType *T) { AddDecl(T->getDecl()); QualType UnderlyingType = T->getDecl()->getUnderlyingType(); diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index b22ccdd0c8..8667a3ad5f 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -2286,6 +2286,127 @@ Invalid1 i1; #undef DECLS } // namespace BaseClass +namespace PointersAndReferences { +#if defined(FIRST) || defined(SECOND) +template struct Wrapper{}; +#endif + +#if defined(FIRST) +struct S1 { + Wrapper x; +}; +#elif defined(SECOND) +struct S1 { + Wrapper x; +}; +#else +S1 s1; +// expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +struct S2 { + Wrapper x; +}; +#elif defined(SECOND) +struct S2 { + Wrapper x; +}; +#else +S2 s2; +// expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +struct S3 { + Wrapper x; +}; +#elif defined(SECOND) +struct S3 { + Wrapper x; +}; +#else +S3 s3; +// expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +struct S4 { + Wrapper x; +}; +#elif defined(SECOND) +struct S4 { + Wrapper x; +}; +#else +S4 s4; +// expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +struct S5 { + Wrapper x; +}; +#elif defined(SECOND) +struct S5 { + Wrapper x; +}; +#else +S5 s5; +// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}} +// expected-note@first.h:* {{declaration of 'x' does not match}} +#endif + +#if defined(FIRST) +struct S6 { + Wrapper x; +}; +#elif defined(SECOND) +struct S6 { + Wrapper x; +}; +#else +S6 s6; +// expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}} +// expected-note@second.h:* {{declaration of 'x' does not match}} +#endif + +#define DECLS \ + Wrapper x1; \ + Wrapper x2; \ + Wrapper x3; \ + Wrapper x4; \ + Wrapper x5; \ + Wrapper x6; \ + Wrapper x7; \ + Wrapper x8; \ + Wrapper x9; + +#if defined(FIRST) || defined(SECOND) +struct Valid1 { + DECLS +}; +#else +Valid1 v1; +#endif + +#if defined(FIRST) || defined(SECOND) +struct Invalid1 { + DECLS + ACCESS +}; +#else +Invalid1 i1; +// expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} +// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} +#endif +#undef DECLS +} // namespace PointersAndReferences + // Collection of interesting cases below. -- 2.40.0