[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)
commit64c80b4e39bbd4dc2b1b3b9b0a1be1eaa3f9c7ed
tree08b054a179032bb7f70f45d94dbaad494310ddad
parentf202365910b9c20a30e26f449dbf6f9b49cf774a
[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

llvm-svn: 285176
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CMakeLists.txt
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/VarBypassDetector.cpp [new file with mode: 0644]
clang/lib/CodeGen/VarBypassDetector.h [new file with mode: 0644]
clang/test/CodeGen/lifetime2.c