[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
Tue Jan 24 13:49:11 PST 2017
ahatanak added inline comments.
================
Comment at: lib/CodeGen/CodeGenFunction.h:217
+ /// statements.
+ llvm::SmallVector<bool, 4> LabelSeenStack;
+
----------------
ahatanak wrote:
> rjmccall wrote:
> > Shouldn't this be maintained by some existing scoping structure like LexicalScope?
> I think I need a structure that gets pushed and popped when we enter and exit a compound statement, but I couldn't find one in CodeGenFunction.
>
> Adding a flag to LexicalScope would fail to disable lifetime markers in some cases. For example, in the code below (which I think is valid), the lifetime markers of "i" wouldn't get disabled because a LexicalScope is pushed at the beginning of CodeGenFunction::EmitForStmt:
>
> ```
> void foo2(int *);
> int c;
>
> void foo1(int n) {
> int *p = 0;
>
> label1:
> foo2(p);
> for (int i = 0; i < n; ++i)
> if (i == 5)
> p = &i;
>
> if (c)
> goto label1;
> }
> ```
>
> If we want to avoid introducing new structures to track labels, perhaps we can just check whether a label was seen so far in the current function rather than the current compound statement, but I'm not sure how much impact that would have on performance.
Alternatively, add a flag to LexicalScope that indicates it was created in EmitCompoundStmtWithoutScope. lifetime markers would be disabled if the flag of the enclosing CompoundStmt's LexicalScope were set.
https://reviews.llvm.org/D27680
More information about the cfe-commits
mailing list