IIUC, we sometimes turn -retain message sends into calls to objc_retain and so on. Outside of ARC (the only time they're valid), these calls don't have the semantics of guaranteeing to return their self argument. So I think this change is only fine if we're not applying it when doing that non-ARC transformation.
I believe this is covered now. The -retain => objc_retain transformation emits normal function calls, and objc_retain calls are only transformed into intrinsic calls when ARC is enabled.
Also, turns out that stripPointerCasts() can see through the thisreturn attribute, which defeats a self retain optimization, breaking one of the clang tests. I tweaked a callback to make it configurable. Let me know if you see a better way of dealing with that.