File: init-invariant.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (60 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download
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
// RUN: %clang_cc1 -no-opaque-pointers -triple i686-linux-gnu -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0
// RUN: %clang_cc1 -no-opaque-pointers -triple i686-linux-gnu -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 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({{.*}}* noundef {{[^,]*}} @a)
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @a to i8*))

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

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

// CHECK: call noundef i32 @_Z1fv(
// CHECK: store {{.*}}, i32* @d
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @d to i8*))

// CHECK-LABEL: define{{.*}} void @_Z1ev(
// CHECK: call void @_ZN1AC1Ev(%struct.A* noundef {{[^,]*}} @_ZZ1evE1a)
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* {{.*}}bitcast ({{.*}} @_ZZ1evE1a to i8*))
// CHECK-NOT: llvm.invariant.end