]> granicus.if.org Git - clang/commit
[CodeGen] Don't emit lifetime intrinsics for some local variables
authorVitaly Buka <vitalybuka@google.com>
Wed, 26 Oct 2016 05:42:30 +0000 (05:42 +0000)
committerVitaly Buka <vitalybuka@google.com>
Wed, 26 Oct 2016 05:42:30 +0000 (05:42 +0000)
commitef66d4d58b9a2c6b3d31bbaf3ed2a70a9754a137
tree692b0d4194963ad98d98470bfb1f1cb0d81a31e9
parent26c2965d0f8434b1b923c32f0f6f4d0ce998e6d2
[CodeGen] Don't emit lifetime intrinsics for some local variables

Summary:
Current generation of lifetime intrinsics does not handle cases like:

```
  {
    char x;
  l1:
    bar(&x, 1);
  }
  goto l1;

```
We will get code like this:

```
  %x = alloca i8, align 1
  call void @llvm.lifetime.start(i64 1, i8* nonnull %x)
  br label %l1
l1:
  %call = call i32 @bar(i8* nonnull %x, i32 1)
  call void @llvm.lifetime.end(i64 1, i8* nonnull %x)
  br label %l1
```

So the second time bar was called for x which is marked as dead.
Lifetime markers here are misleading so it's better to remove them at all.
This type of bypasses are rare, e.g. code detects just 8 functions building
clang (2329 targets).

PR28267

Reviewers: eugenis

Subscribers: beanz, mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D24693

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285176 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/VarBypassDetector.cpp [new file with mode: 0644]
lib/CodeGen/VarBypassDetector.h [new file with mode: 0644]
test/CodeGen/lifetime2.c