]> granicus.if.org Git - llvm/commit
[ObjCARC] Do not sink an objc_retain past a clang.arc.use.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 25 Apr 2017 04:06:35 +0000 (04:06 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 25 Apr 2017 04:06:35 +0000 (04:06 +0000)
commitb86291cfa78caafc8679ef642197952deff6bceb
tree8c7a4f73c0c4a32f93834a6959905807ea8c6218
parent3c385a613bbb8432705ac34837f3bd9ad210eece
[ObjCARC] Do not sink an objc_retain past a clang.arc.use.

We need to do this to prevent a miscompile which sinks an objc_retain
past an objc_release that releases the object objc_retain retains. This
happens because the top-down and bottom-up traversals each determines
the insert point for retain or release individually without knowing
where the other instruction is moved.

For example, when the following IR is fed to the ARC optimizer, the
top-down traversal decides to insert objc_retain right before
objc_release and the bottom-up traversal decides to insert objc_release
right after clang.arc.use.

(IR before ARC optimizer)
%11 = call i8* @objc_retain(i8* %10)
call void (...) @clang.arc.use(%0* %5)
call void @llvm.dbg.value(...)
call void @objc_release(i8* %6)

This reverses the order of objc_release and objc_retain, which causes
the object to be destructed prematurely.

(IR after ARC optimizer)
call void (...) @clang.arc.use(%0* %5)
call void @objc_release(i8* %6)
call void @llvm.dbg.value(...)
%11 = call i8* @objc_retain(i8* %10)

rdar://problem/30530580

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301289 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/ObjCARC/PtrState.cpp
test/Transforms/ObjCARC/clang-arc-use-barrier.ll [new file with mode: 0644]
test/Transforms/ObjCARC/intrinsic-use.ll