[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
Mon Jan 9 13:41:27 PST 2017
ahatanak updated this revision to Diff 83680.
ahatanak added a comment.
Herald added a subscriber: mgorny.
I added an AST analysis pass that is run before IRGen and decides which VarDecls need their lifetimes to be extended or disabled. It only looks at VarDecls which have their addresses taken and are declared after a label is seen. It extends the lifetimes of VarDecls declared in a compound statement if there are backward gotos that don't leave the scope of the compound statement. However, if there are gotos that jump from outside into the compound statement too, it drops all lifetime markers for those VarDecls since emitting lifetime.start at the beginning of the compound statement might break use-after-scope check. For example:
goto label2;
{
// cannot move lifetime.start for "x" to the start of this block since the "goto label2" will
// jump over lifetime.start.
...
label2:
...
label1:
...
int x;
foo1(&x);
goto label1; // backward goto.
}
https://reviews.llvm.org/D27680
Files:
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/LifetimeExtend.cpp
lib/CodeGen/LifetimeExtend.h
test/CodeGen/lifetime2.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27680.83680.patch
Type: text/x-patch
Size: 16650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170109/0a4db3ec/attachment-0001.bin>
More information about the cfe-commits
mailing list