Skip to content

Commit a616cbb

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 (cherry picked from commit c593126)
1 parent 34d2cd9 commit a616cbb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

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

11501150
void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
11511151
struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1152+
struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1153+
if (DD.Definition != NewDD.Definition) {
1154+
Reader.MergedDeclContexts.insert(
1155+
std::make_pair(NewDD.Definition, DD.Definition));
1156+
}
1157+
11521158
// FIXME: odr checking?
11531159
}
11541160

clang/test/Modules/odr_hash.mm

Lines changed: 11 additions & 8 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 x; // FIXME: align with upstream (rdar://43906928).
244+
T y; // FIXME: align with upstream (rdar://43906928).
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,17 @@ @interface Interface4 <T : I1 *> {
257257
@end
258258
@interface Interface5 <T : I1 *> {
259259
@public
260-
T x; // FIXME: align with upstream (rdar://43906928).
260+
T y; // FIXME: align with upstream (rdar://43906928).
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]:* {{'Interface6::z' from module 'FirstModule' is not present in definition of 'Interface6' in module 'SecondModule'}}
270+
// [email protected]:* {{declaration of 'z' does not match}}
268271
#endif
269272

270273
namespace Types {
@@ -276,18 +279,18 @@ @interface Interface6 <T1 : I1 *, T2 : I2 *> {
276279
};
277280
struct Invalid2 {
278281
Interface5 *I;
279-
decltype(I->x) x;
282+
decltype(I->y) y;
280283
};
281284
struct Invalid3 {
282285
Interface6 *I;
283-
decltype(I->x) x;
286+
decltype(I->z) z;
284287
};
285288
#else
286289
Invalid1 i1;
287290
Invalid2 i2;
288291
Invalid3 i3;
289-
// [email protected]:* {{'Types::ObjCTypeParam::Invalid3::x' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' in module 'SecondModule'}}
290-
// [email protected]:* {{declaration of 'x' does not match}}
292+
// [email protected]:* {{'Types::ObjCTypeParam::Invalid3::z' from module 'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' in module 'SecondModule'}}
293+
// [email protected]:* {{declaration of 'z' does not match}}
291294
#endif
292295

293296
} // namespace ObjCTypeParam

0 commit comments

Comments
 (0)