
Following the previous patch which adds the "extend lifetimes" flag without (almost) any functionality, this patch adds the real feature by allowing Clang to emit fake uses. These are emitted as a new form of cleanup, set for variable addresses, which just emits a fake use intrinsic when the variable falls out of scope. The code for achieving this is simple, with most of the logic centered on determining whether to emit a fake use for a given address, and on ensuring that fake uses are ignored in a few cases. Co-authored-by: Stephen Tozer <stephen.tozer@sony.com>
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
// RUN: %clang_cc1 %s -triple=%itanium_abi_triple -O1 -emit-llvm -fextend-variable-liveness -o - | FileCheck %s
|
|
// Make sure we don't crash compiling a lambda that is not nested in a function.
|
|
// We also check that fake uses are properly issued in lambdas.
|
|
|
|
int glob;
|
|
|
|
extern int foo();
|
|
|
|
struct S {
|
|
static const int a;
|
|
};
|
|
|
|
const int S::a = [](int b) __attribute__((noinline)) {
|
|
return b * foo();
|
|
}
|
|
(glob);
|
|
|
|
int func(int param) {
|
|
return ([=](int lambdaparm) __attribute__((noinline))->int {
|
|
int lambdalocal = lambdaparm * 2;
|
|
return lambdalocal;
|
|
}(glob));
|
|
}
|
|
|
|
// We are looking for the first lambda's call operator, which should contain
|
|
// 2 fake uses, one for 'b' and one for its 'this' pointer (in that order).
|
|
// The mangled function name contains a $_0, followed by 'cl'.
|
|
// This lambda is an orphaned lambda, i.e. one without lexical parent.
|
|
//
|
|
// CHECK-LABEL: define internal {{.+\"_Z.+\$_0.*cl.*\"}}
|
|
// CHECK-NOT: ret
|
|
// CHECK: fake.use(i32
|
|
// CHECK-NOT: ret
|
|
// CHECK: fake.use(ptr
|
|
|
|
// The second lambda. We are looking for 3 fake uses.
|
|
// CHECK-LABEL: define internal {{.+\"_Z.+\$_0.*cl.*\"}}
|
|
// CHECK-NOT: ret
|
|
// CHECK: fake.use(i32
|
|
// CHECK-NOT: ret
|
|
// CHECK: fake.use(i32
|
|
// CHECK-NOT: ret
|
|
// CHECK: fake.use(ptr
|