New ObjC warning: circular containers.
authorAlex Denisov <1101.debian@gmail.com>
Wed, 4 Mar 2015 17:55:52 +0000 (17:55 +0000)
committerAlex Denisov <1101.debian@gmail.com>
Wed, 4 Mar 2015 17:55:52 +0000 (17:55 +0000)
commite1d882c726b53eebe4dbece9fdf7fb8dc6469f72
tree60507712962fd8ed3cca070487229c64a1052884
parent4d9347993bbaaf9278df52d14e71e460a4afbd9f
New ObjC warning: circular containers.

This commit adds new warning to prevent user from creating 'circular containers'.

Mutable collections from NSFoundation allows user to add collection to itself, e.g.:

NSMutableArray *a = [NSMutableArray new];
[a addObject:a];

The code above leads to really weird behaviour (crashes, 'endless' recursion) and
retain cycles (collection retains itself) if ARC enabled.

Patch checks the following collections:
  - NSMutableArray,
  - NSMutableDictionary,
  - NSMutableSet,
  - NSMutableOrderedSet,
  - NSCountedSet.

llvm-svn: 231265
clang/include/clang/AST/NSAPI.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/NSAPI.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/test/SemaObjC/circular-container.m [new file with mode: 0644]