Page MenuHomePhabricator

[objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls
ClosedPublic

Authored by kubamracek on Jun 29 2017, 1:35 PM.

Details

Summary

There's currently an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. The following code triggers an ASan use-after-scope report:

MyClass *myNil = nil;  // intentionally nil
[myNil methodWhichReturnsARect];

The reason is that when the result of a struct-returning call is ignore, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes the use-after-scope problem.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek created this revision.Jun 29 2017, 1:35 PM
rjmccall edited edge metadata.Jun 29 2017, 1:58 PM

Please include an IRGen test directly for the lifetime marker emission you want, and please make sure you test the ns_consumed argument + ignored stret result case.

tools/clang/lib/CodeGen/CGObjCMac.cpp
2147 ↗(On Diff #104728)

Please add a comment here, something like "We don't need to emit a null check to zero out an indirect result if the result is ignored."

Adding a test, updating the comment.

rjmccall accepted this revision.Jun 29 2017, 8:44 PM

Thanks, looks great.

This revision is now accepted and ready to land.Jun 29 2017, 8:44 PM
This revision was automatically updated to reflect the committed changes.