File: init-invariant.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (73 lines) | stat: -rw-r--r-- 1,932 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s

// Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes
// read-only. If globalopt can fold the initializer, it will then mark the
// variable as constant.

// Do not produce markers at -O0.
// CHECK-O0-NOT: llvm.invariant.start.p0i8

struct A {
  A();
  int n;
};

// CHECK: @a ={{.*}} global {{.*}} zeroinitializer
extern const A a = A();

struct A2 {
  A2();
  constexpr ~A2() {}
  int n;
};

// CHECK: @a2 ={{.*}} global {{.*}} zeroinitializer
extern const A2 a2 = A2();


struct B {
  B();
  mutable int n;
};

// CHECK: @b ={{.*}} global {{.*}} zeroinitializer
extern const B b = B();

struct C {
  C();
  ~C();
  int n;
};

// CHECK: @c ={{.*}} global {{.*}} zeroinitializer
extern const C c = C();

int f();
// CHECK: @d ={{.*}} global i32 0
extern const int d = f();

void e() {
  static const A a = A();
}

// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @a)
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a)

// CHECK: call void @_ZN2A2C1Ev(ptr noundef {{[^,]*}} @a2)
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a2)

// CHECK: call void @_ZN1BC1Ev(ptr noundef {{[^,]*}} @b)
// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @b)

// CHECK: call void @_ZN1CC1Ev(ptr noundef {{[^,]*}} @c)
// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @c)

// CHECK: call noundef i32 @_Z1fv(
// CHECK: store {{.*}}, ptr @d
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d)

// CHECK-LABEL: define{{.*}} void @_Z1ev(
// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)
// CHECK-NOT: llvm.invariant.end