[PATCH] D27680: [CodeGen] Move lifetime.start of a variable when goto jumps back past its declaration

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 15:21:39 PST 2017

ahatanak added a comment.

In https://reviews.llvm.org/D27680#642770, @rjmccall wrote:

> Interesting.  That's a pretty heavyweight solution, and you're still missing switches, which have exactly the same "can jump into an arbitrary variable's scope" behavior.

In addition to missing the switches, I realized the code in VisitGotoStmt and VisitLabelStmt isn't correct. For example, in function move_lifetime_start in the test case, it wouldn't move the lifetime markers for "i "if label "label1" were enclosed in a block:

     p = 0;
    int i = 999;
    if (ac != 2) {
      p = &i;
      goto label1;

I fixed both bugs in my local branch.

> I think maybe an easier solution would be to just remove the begin-lifetime marker completely when there's a label or case statement in its scope.  If we want to improve on that, there's already a jump analysis in Sema that could pretty easily be made to mark variables that have jumps into their lifetimes; we would just need to guarantee that that analysis is done.

I suppose you are suggesting we avoid emitting lifetime begin and end during IRGen if there is a label preceding the variable declaration (I don't think we have to care about case or default statements since we only have to worry about backward jumps), rather than running an analysis pass before IRGen and stretching the lifetime at IRGen time. If it doesn't have a large impact on performance, we can do that, but otherwise we have to come up with another way to fix this bug.


More information about the cfe-commits mailing list