llvm/lib/Transforms/ObjCARC
Michael Gottesman 0556900b26 [objc-arc] Do not mismatch up retains inside a for loop with releases outside said for loop in the presense of differing provenance caused by escaping blocks.
This occurs due to an alloca representing a separate ownership from the
original pointer. Thus consider the following pseudo-IR:

  objc_retain(%a)
  for (...) {
    objc_retain(%a)
    %block <- %a
    F(%block)
    objc_release(%block)
  }
  objc_release(%a)

From the perspective of the optimizer, the %block is a separate
provenance from the original %a. Thus the optimizer pairs up the inner
retain for %a and the outer release from %a, resulting in segfaults.

This is fixed by noting that the signature of a mismatch of
retain/releases inside the for loop is a Use/CanRelease top down with an
None bottom up (since bottom up the Retain-CanRelease-Use-Release
sequence is completed by the inner objc_retain, but top down due to the
differing provenance from the objc_release said sequence is not
completed). In said case in CheckForCFGHazards, we now clear the state
of %a implying that no pairing will occur.

Additionally a test case is included.

rdar://12969722

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179747 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-18 05:39:45 +00:00
..
CMakeLists.txt Extracted ObjCARCContract from ObjCARCOpts into its own file. 2013-01-29 03:03:03 +00:00
DependencyAnalysis.cpp Kill every call to @clang.arc.use in the ARC contract phase. 2013-03-22 21:38:36 +00:00
DependencyAnalysis.h Extracted ObjCARCContract from ObjCARCOpts into its own file. 2013-01-29 03:03:03 +00:00
LLVMBuild.txt Added missing dashes from header declaration comment. 2013-01-29 04:53:55 +00:00
Makefile
ObjCARC.cpp [objc-arc] Added descriptions for EnableARCAnnotations, EnableCheckForCFGHazards, EnableARCOptimizations. 2013-04-17 20:48:03 +00:00
ObjCARC.h Add clang.arc.used to ModuleHasARC so ARC always runs if said call is present in a module. 2013-03-29 21:15:23 +00:00
ObjCARCAliasAnalysis.cpp Sorted includes using utils/sort_includes. 2013-01-29 04:20:52 +00:00
ObjCARCAliasAnalysis.h Added two missing headers from ObjCARCAliasAnalysis.h. 2013-01-29 04:09:24 +00:00
ObjCARCAPElim.cpp Hopefully fix the Windows build failure introduced in r173769 2013-01-29 09:09:27 +00:00
ObjCARCContract.cpp Changed isNullOrUndef => IsNullOrUndef and isNoopInstruction => IsNoopInstruction so that all helper functions are named similarly in ObjCARC.h. 2013-03-25 09:27:43 +00:00
ObjCARCExpand.cpp Sorted includes using utils/sort_includes. 2013-01-29 04:20:52 +00:00
ObjCARCOpts.cpp [objc-arc] Do not mismatch up retains inside a for loop with releases outside said for loop in the presense of differing provenance caused by escaping blocks. 2013-04-18 05:39:45 +00:00
ObjCARCUtil.cpp [ObjCARC Annotations] Added support for displaying the state of pointers at the bottom/top of BBs of the ARC dataflow analysis for both bottomup and topdown analyses. 2013-03-26 00:42:09 +00:00
ProvenanceAnalysis.cpp Changed isStoredObjCPointer => IsStoredObjCPointer. No functionality change. 2013-02-12 23:35:08 +00:00
ProvenanceAnalysis.h Fixed some whitespace/80+ violations. Also added a space after a namespace declaration. 2013-01-29 04:58:30 +00:00