[PATCH] D118525: [modules] Merge ObjC interface ivars with anonymous types.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 28 19:53:59 PST 2022


vsapsai created this revision.
vsapsai added reviewers: ahatanak, rsmith.
vsapsai added a project: clang-modules.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.

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.  Though for
anonymous `TagDecl` `ObjCContainerDecl` is both a lexical and a semantic
decl context now. But it doesn't affect the lookup because such
`TagDecl`s don't have a name to use for the lookup.

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

rdar://85563013


Repository:
  rC Clang

https://reviews.llvm.org/D118525

Files:
  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
  clang/test/SemaObjC/check-dup-decls-inside-objc.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118525.404220.patch
Type: text/x-patch
Size: 10743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220129/74398f58/attachment-0001.bin>


More information about the cfe-commits mailing list