-Warc-repeated-use-of-weak: allow single reads in loops from local variables.
authorJordan Rose <jordan_rose@apple.com>
Mon, 29 Oct 2012 17:46:47 +0000 (17:46 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 29 Oct 2012 17:46:47 +0000 (17:46 +0000)
commit25c0ea8995950ba8f4c53cd3e8252f6cfb0947a7
tree164a3650073bddd05e193104d7c54f5b95f4edaf
parentec44ac6a59d24c02c2f6036efcfb511b5608e009
-Warc-repeated-use-of-weak: allow single reads in loops from local variables.

Previously, the warning would erroneously fire on this:

for (Test *a in someArray)
  use(a.weakProp);

...because it looks like the same property is being accessed over and over.
However, clearly this is not the case. We now ignore loops like this for
local variables, but continue to warn if the base object is a parameter,
global variable, or instance variable, on the assumption that these are
not repeatedly usually assigned to within loops.

Additionally, do-while loops where the condition is 'false' are not really
loops at all; usually they're just used for semicolon-swallowing macros or
using "break" like "goto".

<rdar://problem/12578785&12578849>

llvm-svn: 166942
clang/include/clang/Sema/ScopeInfo.h
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/test/SemaObjC/arc-repeated-weak.mm