This is an archive of the discontinued LLVM Phabricator instance.

[LangRef] State that a nocapture pointer cannot be returned
ClosedPublic

Authored by aqjune on Jan 10 2021, 9:44 PM.

Details

Summary

This is a small patch stating that a nocapture pointer cannot be returned.

Discussed in D93189.

Diff Detail

Event Timeline

aqjune requested review of this revision.Jan 10 2021, 9:44 PM
aqjune created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2021, 9:44 PM

Should we add the, "if broken -> UB!" clause while we are here?

Should we add the, "if broken -> UB!" clause while we are here?

That's a good point, but I think there are a few candidate semantics and I'm not sure which one is the best.
It can be (1) UB, or (2) the stored pointer magically turns into poison when it returns. Also, it isn't certain when the program should raise UB (during the execution of the callee, or when the callee finally returns).
Diving into this issue more, it can be indirectly captured using ptr-int casts:

if (p == 0x100) {
  escape ((i8*)0x100);
}

So, TBH, I'd like to make this patch just a simple step clarifying that nocapture pointer cannot be returned. :/ Making a further step might require as much discussion as lifetime/nonnull.
(BTW, for the lifetime patch, I'm still interested in making further progress; I'm busy until the end of Jan, I'll restart working on it after the busy thing is done.)

jdoerfert accepted this revision.Jan 12 2021, 7:55 AM

This spells out uncontroversial effective semantics, so LGTM.

This revision is now accepted and ready to land.Jan 12 2021, 7:55 AM