File: fake-use-lambda.cpp

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (43 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 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