[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt [take 2]
authorKuba Mracek <mracek@apple.com>
Fri, 14 Apr 2017 16:53:25 +0000 (16:53 +0000)
committerKuba Mracek <mracek@apple.com>
Fri, 14 Apr 2017 16:53:25 +0000 (16:53 +0000)
commit5e5e4e790f8758000fe08bc784d9cf6187d5e950
treefc2656862ecceb04699f2f9a30ec05e1fce8b7ba
parent01545beb75566e16db480e929068f6cd9f3b98ef
[ObjC] Fix lifetime markers of loop variable in EmitObjCForCollectionStmt [take 2]

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). This patch keeps the loop variable alive for the whole loop by extending ForScope and registering the cleanup function inside EmitAutoVarAlloca.

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

llvm-svn: 300340
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/arc-blocks.m
clang/test/CodeGenObjCXX/arc-references.mm