[modules] Merge ObjC interface ivars with anonymous types.
authorVolodymyr Sapsai <vsapsai@apple.com>
Sat, 29 Jan 2022 01:08:21 +0000 (17:08 -0800)
committerVolodymyr Sapsai <vsapsai@apple.com>
Tue, 5 Apr 2022 01:48:30 +0000 (18:48 -0700)
commit29444f0444c6d3586969fd6fbe49c8188c02c244
treec62ccf5209c8081b1a9b92c813235c1f788cdb8b
parentc7bd9dcb064cc258c97a46f5b473b390360b548e
[modules] Merge ObjC interface ivars with anonymous types.

Without the fix ivars with anonymous types can trigger errors like

> error: 'TestClass::structIvar' from module 'Target' is not present in definition of 'TestClass' provided earlier
> [...]
> note: declaration of 'structIvar' does not match

It happens because types of ivars from different modules are considered
to be different. And it is caused by not merging anonymous `TagDecl`
from different modules.

To fix that I've changed `serialization::needsAnonymousDeclarationNumber`
to handle anonymous `TagDecl` inside `ObjCInterfaceDecl`. But that's not
sufficient as C code inside `ObjCInterfaceDecl` doesn't use interface
decl as a decl context but switches to its parent (TranslationUnit in
most cases).  I'm changing that to make `ObjCContainerDecl` the lexical
decl context but keeping the semantic decl context intact.

Test "check-dup-decls-inside-objc.m" doesn't reflect a change in
functionality but captures the existing behavior to prevent regressions.

rdar://85563013

Differential Revision: https://reviews.llvm.org/D118525
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/AST/ast-dump-decl.mm
clang/test/Modules/merge-anon-record-definition-in-objc.m [new file with mode: 0644]
clang/test/SemaObjC/check-dup-decls-inside-objc.m [new file with mode: 0644]