Skip to content

Commit c593126

Browse files
committed
[modules] While merging ObjCInterfaceDecl definitions, merge them as decl contexts too.
While working on https://reviews.llvm.org/D110280 I've tried to merge decl contexts as it seems to be correct and matching our handling of decl contexts from different modules. It's not required for the fix in https://reviews.llvm.org/D110280 but it revealed a missing diagnostic, so separating this change into a separate commit. Renamed some variables to distinguish diagnostic like "declaration of 'x' does not match" for different cases. Differential Revision: https://reviews.llvm.org/D110287
1 parent dc2be87 commit c593126

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,12 @@ void ASTDeclReader::ReadObjCDefinitionData(
11771177

11781178
void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
11791179
struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1180+
struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1181+
if (DD.Definition != NewDD.Definition) {
1182+
Reader.MergedDeclContexts.insert(
1183+
std::make_pair(NewDD.Definition, DD.Definition));
1184+
}
1185+
11801186
// FIXME: odr checking?
11811187
}
11821188

clang/test/Modules/odr_hash.mm

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ @interface Interface4 <T : I1 *> {
241241
@end
242242
@interface Interface5 <T : I1 *> {
243243
@public
244-
T<P1> x;
244+
T<P1> y;
245245
}
246246
@end
247247
@interface Interface6 <T1 : I1 *, T2 : I2 *> {
248248
@public
249-
T1 x;
249+
T1 z;
250250
}
251251
@end
252252
#elif defined(SECOND)
@@ -257,14 +257,21 @@ @interface Interface4 <T : I1 *> {
257257
@end
258258
@interface Interface5 <T : I1 *> {
259259
@public
260-
T<P1, P2> x;
260+
T<P1, P2> y;
261261
}
262262
@end
263263
@interface Interface6 <T1 : I1 *, T2 : I2 *> {
264264
@public
265-
T2 x;
265+
T2 z;
266266
}
267267
@end
268+
#else
269+
// [email protected]:* {{'Interface4::x' from module 'FirstModule' is not present in definition of 'Interface4' in module 'SecondModule'}}
270+
// [email protected]:* {{declaration of 'x' does not match}}
271+
// [email protected]:* {{'Interface5::y' from module 'FirstModule' is not present in definition of 'Interface5' in module 'SecondModule'}}
272+
// [email protected]:* {{declaration of 'y' does not match}}
273+
// [email protected]:* {{'Interface6::z' from module 'FirstModule' is not present in definition of 'Interface6' in module 'SecondModule'}}
274+
// [email protected]:* {{declaration of 'z' does not match}}
268275
#endif
269276

270277
namespace Types {
@@ -276,22 +283,22 @@ @interface Interface6 <T1 : I1 *, T2 : I2 *> {
276283
};
277284
struct Invalid2 {
278285
Interface5 *I;
279-
decltype(I->x) x;
286+
decltype(I->y) y;
280287
};
281288
struct Invalid3 {
282289
Interface6 *I;
283-
decltype(I->x) x;
290+
decltype(I->z) z;
284291
};
285292
#else
286293
Invalid1 i1;
287294
// [email protected]:* {{'Types::ObjCTypeParam::Invalid1::x' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid1' in module 'SecondModule'}}
288295
// [email protected]:* {{declaration of 'x' does not match}}
289296
Invalid2 i2;
290-
// [email protected]:* {{'Types::ObjCTypeParam::Invalid2::x' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid2' in module 'SecondModule'}}
291-
// [email protected]:* {{declaration of 'x' does not match}}
297+
// [email protected]:* {{'Types::ObjCTypeParam::Invalid2::y' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid2' in module 'SecondModule'}}
298+
// [email protected]:* {{declaration of 'y' does not match}}
292299
Invalid3 i3;
293-
// [email protected]:* {{'Types::ObjCTypeParam::Invalid3::x' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' in module 'SecondModule'}}
294-
// [email protected]:* {{declaration of 'x' does not match}}
300+
// [email protected]:* {{'Types::ObjCTypeParam::Invalid3::z' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' in module 'SecondModule'}}
301+
// [email protected]:* {{declaration of 'z' does not match}}
295302
#endif
296303

297304
} // namespace ObjCTypeParam

0 commit comments

Comments
 (0)