[LLVMdev] lifetime.start/end clarification
Philip Reames
listmail at philipreames.com
Wed Nov 5 11:36:12 PST 2014
On 11/05/2014 11:08 AM, Arnaud A. de Grandmaison wrote:
>
> *From:*Philip Reames [mailto:listmail at philipreames.com]
> *Sent:* 05 November 2014 19:25
> *To:* Reid Kleckner
> *Cc:* Arnaud De Grandmaison; Nick Lewycky; Rafael Ávila de Espíndola;
> LLVM Developers Mailing List
> *Subject:* Re: [LLVMdev] lifetime.start/end clarification
>
> On 11/05/2014 10:10 AM, Reid Kleckner wrote:
>
> On Wed, Nov 5, 2014 at 10:01 AM, Philip Reames
> <listmail at philipreames.com <mailto:listmail at philipreames.com>> wrote:
>
> Would one of you mind taking a step back and explaining what you
> believe the "stack colouring problem" to be? I'm familiar with
> the general meaning of the term and even some of LLVM's
> implementation; I'm just not sure what specific issue you're
> referring to. Having the context would make it much easier to
> assess your proposals.
>
> The goal of stack coloring is to reduce stack usage by storing
> user data with non-overlapping lifetimes in the same stack memory.
>
> C/C++ source programs usually have a naturally scoped structure,
> where the lifetime of data is bounded by curly braces. This
> information reduces the lifetime that stack coloring sees, so it
> saves stack memory.
>
> When we go to LLVM IR, we lose all that information. We currently
> try to recapture it with calls to @lifetime.start / end intrinsic
> calls at the point of declaration and when the variable falls out
> of scope. Basically we're trying to figure out how to put that
> scoping information back into the IR without turning it back into
> a tree.
>
> Furthermore, if we had better information about this in the IR, we
> could augment ASan to detect use-after-scope.
>
> Everything you say here is general goodness. What part of this is
> problematic today? My belief is that the lifetime markers give you
> exactly the support you need. Where does this break down? Is the
> analysis too hard? Is Clang getting the semantics wrong? What's the
> actually blocking issue?
>
> Here is the actually blocking issue. Today, the lifetime markers are
> only inserted if the alloca is big enough (32+ bytes). I tried several
> times to add the lifetime markers for unnamed temporaries; the patches
> have been reviewed each time by people knowledgeable with this part of
> clang. But when we remove the size limit for the lifetime marker
> insertion, we get miscompiles when bootstrapping clang. This is why I
> was asking for clarification of the specification, as this is a part I
> found left room for interpretation.
>
Ah, okay. The context helps. Unfortunately, I think you're going to
have to do this the hard way. Find a miscompile, reduce it down to an
analysable test case, and then identify the bug. I don't envy you the
experience. :( You might try running a build with restricted
optimization (say, no inlining) to see if you can isolate a small test case.
My (completely unsupported) guess would be that you're going find
undefined behaviour in clang which is being exploited by the optimizer.
Would any of the sanitizers help with this? If not, you could try the
naive version: generate a clobbering store in place of the lifetime
intrinsic, see if you can make it crash.
Philip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141105/48192d5e/attachment.html>
More information about the llvm-dev
mailing list