[all-commits] [llvm/llvm-project] 02899d: [clang] Don't make ObjCIvarDecl visible twice when...

Raphael Isemann via All-commits all-commits at lists.llvm.org
Tue Aug 11 07:25:25 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 02899d7f1b9ae7f6da30bd020a714c7b3eb2c59f
      https://github.com/llvm/llvm-project/commit/02899d7f1b9ae7f6da30bd020a714c7b3eb2c59f
  Author: Raphael Isemann <teemperor at gmail.com>
  Date:   2020-08-11 (Tue, 11 Aug 2020)

  Changed paths:
    M clang/lib/Sema/SemaDeclObjC.cpp

  Log Message:
  -----------
  [clang] Don't make ObjCIvarDecl visible twice when adding them to an implicit ObjCInterfaceDecl

`addDecl` is making the ivar visible in its primary context. The primary context
of the ivar here is in a 'fragile' ABI the ObjCInterfaceDecl and in a
'non-fragile' ABI the current ObjCImplementationDecl. The additional call to
`makeDeclVisibleInContext` to make the ivar visible in the ObjCInterfaceDecl is
only necessary in the 'non-fragile' case (as in the 'fragile' case the Decl
becomes automatically visible in the ObjCInterfaceDecl with the `addDecl` call
as thats its primary context). See `Sema::ActOnIvar` for where the ivar is put
into a different context depending on the ABI.

To put this into an example:

```
lang=c++
@implementation SomeClass
{
  id ivar1;
}
@end

fragile case:
implicit ObjCInterfaceDecl 'SomeClass'
`- ivar1 (in primary context and will be automatically made visible)
ObjCImplementationDecl 'SomeClass'

non-fragile case:
implicit ObjCInterfaceDecl 'SomeClass'
`-<<<ivar1 not visible here and needs to be manually marked as visible.>>>
ObjCImplementationDecl 'SomeClass'
`- ivar1 (in its primary context and will be automatically made visible here)
```

Making a Decl visible multiple times in the same context is inefficient and
potentially can lead to crashes. See D84827 for more info and what this is
breaking.

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D84829




More information about the All-commits mailing list