[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt
authorKuba Mracek <mracek@apple.com>
Fri, 14 Apr 2017 00:32:43 +0000 (00:32 +0000)
committerKuba Mracek <mracek@apple.com>
Fri, 14 Apr 2017 00:32:43 +0000 (00:32 +0000)
commit8f56846d4f86efc9dccd5b64d569878191dcaaf5
tree79ccbaed9c92bf916cb0c370c78e97e28fe470f0
parentc7b9ecaa6303ec38ac397f04ca83581fa7a74414
[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt

CodeGenFunction::EmitObjCForCollectionStmt currently emits lifetime markers for the loop variable in an inconsistent way:  lifetime.start is emitted before the loop is entered, but lifetime.end is emitted inside the loop.  AddressSanitizer uses these markers to track out-of-scope accesses to local variables, and we get false positives in Obj-C foreach loops (in the 2nd iteration of the loop). The markers of the loop variable need to be either both inside the loop (so that we poison and unpoison the variable in each iteration), or both outside. This patch implements the "both inside" approach.

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

llvm-svn: 300287
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/arc-foreach.m
clang/test/CodeGenObjC/arc-ternary-op.m