[PATCH] D93376: [LangRef] Clarify the semantics of lifetime intrinsics

Ralf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 00:55:16 PST 2020


RalfJung added a comment.

> Why wouldn't/shouldn't it mean exactly what it means for stack allocations?
> "The memory region specified in the lifetime start is dead until a lifetime start makes that memory accessible, ..."

lifetime.start also has a magic effect "backward in time": when you just do alloca, it allocates some memory. When you do alloca and later do lifetime.start on the resulting pointer, (stack) memory allocation is delayed until the lifetime.start. IOW, lifetime.start is a very unusual intrinsic. Adding it *later* in the code can make a pointer *earlier* in the code dangling.

How do you propose to be able to predict if an alloca actually allocates memory, if it is legal do to something like "%p = alloca (...)", followed by calling "f(p)", followed by "lifetime.start(p)" inside "f"? Now whether the original alloca actually allocates memory depends on the source code of another function...?

Possibly a better fix is to avoid this "magic backward in time" effect, and instead use a flag on alloca to reflect whether memory is immediately allocated, or not. (The details of the semantics of this could still be tricky though.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93376/new/

https://reviews.llvm.org/D93376



More information about the llvm-commits mailing list