head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.6
	netbsd-11-0-RC3:1.1.1.6
	netbsd-11-0-RC2:1.1.1.6
	netbsd-11-0-RC1:1.1.1.6
	perseant-exfatfs-base-20250801:1.1.1.6
	netbsd-11:1.1.1.6.0.10
	netbsd-11-base:1.1.1.6
	netbsd-10-1-RELEASE:1.1.1.6
	perseant-exfatfs-base-20240630:1.1.1.6
	perseant-exfatfs:1.1.1.6.0.8
	perseant-exfatfs-base:1.1.1.6
	netbsd-8-3-RELEASE:1.1.1.4
	netbsd-9-4-RELEASE:1.1.1.5
	netbsd-10-0-RELEASE:1.1.1.6
	netbsd-10-0-RC6:1.1.1.6
	netbsd-10-0-RC5:1.1.1.6
	netbsd-10-0-RC4:1.1.1.6
	netbsd-10-0-RC3:1.1.1.6
	netbsd-10-0-RC2:1.1.1.6
	netbsd-10-0-RC1:1.1.1.6
	netbsd-10:1.1.1.6.0.6
	netbsd-10-base:1.1.1.6
	netbsd-9-3-RELEASE:1.1.1.5
	cjep_sun2x:1.1.1.6.0.4
	cjep_sun2x-base:1.1.1.6
	cjep_staticlib_x-base1:1.1.1.6
	netbsd-9-2-RELEASE:1.1.1.5
	cjep_staticlib_x:1.1.1.6.0.2
	cjep_staticlib_x-base:1.1.1.6
	netbsd-9-1-RELEASE:1.1.1.5
	phil-wifi-20200421:1.1.1.6
	phil-wifi-20200411:1.1.1.6
	phil-wifi-20200406:1.1.1.6
	netbsd-8-2-RELEASE:1.1.1.4
	netbsd-9-0-RELEASE:1.1.1.5
	netbsd-9-0-RC2:1.1.1.5
	netbsd-9-0-RC1:1.1.1.5
	netbsd-9:1.1.1.5.0.6
	netbsd-9-base:1.1.1.5
	phil-wifi-20190609:1.1.1.5
	netbsd-8-1-RELEASE:1.1.1.4
	netbsd-8-1-RC1:1.1.1.4
	pgoyette-compat-merge-20190127:1.1.1.5
	pgoyette-compat-20190127:1.1.1.5
	pgoyette-compat-20190118:1.1.1.5
	pgoyette-compat-1226:1.1.1.5
	pgoyette-compat-1126:1.1.1.5
	pgoyette-compat-1020:1.1.1.5
	pgoyette-compat-0930:1.1.1.5
	pgoyette-compat-0906:1.1.1.5
	netbsd-7-2-RELEASE:1.1.1.2
	pgoyette-compat-0728:1.1.1.5
	clang-337282:1.1.1.5
	netbsd-8-0-RELEASE:1.1.1.4
	phil-wifi:1.1.1.5.0.4
	phil-wifi-base:1.1.1.5
	pgoyette-compat-0625:1.1.1.5
	netbsd-8-0-RC2:1.1.1.4
	pgoyette-compat-0521:1.1.1.5
	pgoyette-compat-0502:1.1.1.5
	pgoyette-compat-0422:1.1.1.5
	netbsd-8-0-RC1:1.1.1.4
	pgoyette-compat-0415:1.1.1.5
	pgoyette-compat-0407:1.1.1.5
	pgoyette-compat-0330:1.1.1.5
	pgoyette-compat-0322:1.1.1.5
	pgoyette-compat-0315:1.1.1.5
	netbsd-7-1-2-RELEASE:1.1.1.2
	pgoyette-compat:1.1.1.5.0.2
	pgoyette-compat-base:1.1.1.5
	netbsd-7-1-1-RELEASE:1.1.1.2
	clang-319952:1.1.1.5
	matt-nb8-mediatek:1.1.1.4.0.10
	matt-nb8-mediatek-base:1.1.1.4
	clang-309604:1.1.1.5
	perseant-stdc-iso10646:1.1.1.4.0.8
	perseant-stdc-iso10646-base:1.1.1.4
	netbsd-8:1.1.1.4.0.6
	netbsd-8-base:1.1.1.4
	prg-localcount2-base3:1.1.1.4
	prg-localcount2-base2:1.1.1.4
	prg-localcount2-base1:1.1.1.4
	prg-localcount2:1.1.1.4.0.4
	prg-localcount2-base:1.1.1.4
	pgoyette-localcount-20170426:1.1.1.4
	bouyer-socketcan-base1:1.1.1.4
	pgoyette-localcount-20170320:1.1.1.4
	netbsd-7-1:1.1.1.2.0.10
	netbsd-7-1-RELEASE:1.1.1.2
	netbsd-7-1-RC2:1.1.1.2
	clang-294123:1.1.1.4
	netbsd-7-nhusb-base-20170116:1.1.1.2
	bouyer-socketcan:1.1.1.4.0.2
	bouyer-socketcan-base:1.1.1.4
	clang-291444:1.1.1.4
	pgoyette-localcount-20170107:1.1.1.3
	netbsd-7-1-RC1:1.1.1.2
	pgoyette-localcount-20161104:1.1.1.3
	netbsd-7-0-2-RELEASE:1.1.1.2
	localcount-20160914:1.1.1.3
	netbsd-7-nhusb:1.1.1.2.0.8
	netbsd-7-nhusb-base:1.1.1.2
	clang-280599:1.1.1.3
	pgoyette-localcount-20160806:1.1.1.3
	pgoyette-localcount-20160726:1.1.1.3
	pgoyette-localcount:1.1.1.3.0.2
	pgoyette-localcount-base:1.1.1.3
	netbsd-7-0-1-RELEASE:1.1.1.2
	clang-261930:1.1.1.3
	netbsd-7-0:1.1.1.2.0.6
	netbsd-7-0-RELEASE:1.1.1.2
	netbsd-7-0-RC3:1.1.1.2
	netbsd-7-0-RC2:1.1.1.2
	netbsd-7-0-RC1:1.1.1.2
	clang-237755:1.1.1.2
	clang-232565:1.1.1.2
	clang-227398:1.1.1.2
	tls-maxphys-base:1.1.1.2
	tls-maxphys:1.1.1.2.0.4
	netbsd-7:1.1.1.2.0.2
	netbsd-7-base:1.1.1.2
	clang-215315:1.1.1.2
	clang-209886:1.1.1.2
	yamt-pagecache:1.1.1.1.0.4
	yamt-pagecache-base9:1.1.1.1
	tls-earlyentropy:1.1.1.1.0.2
	tls-earlyentropy-base:1.1.1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2-base3:1.1.1.1
	clang-202566:1.1.1.1
	clang-201163:1.1.1.1
	clang-199312:1.1.1.1
	clang-198450:1.1.1.1
	clang-196603:1.1.1.1
	clang-195771:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@// @;


1.1
date	2013.11.28.14.14.58;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	ow8OybrawrB1f3fx;

1.1.1.1
date	2013.11.28.14.14.58;	author joerg;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	1.1.1.2;
commitid	ow8OybrawrB1f3fx;

1.1.1.2
date	2014.05.30.18.14.47;	author joerg;	state Exp;
branches
	1.1.1.2.4.1;
next	1.1.1.3;
commitid	8q0kdlBlCn09GACx;

1.1.1.3
date	2016.02.27.22.10.24;	author joerg;	state Exp;
branches
	1.1.1.3.2.1;
next	1.1.1.4;
commitid	tIimz3oDlh1NpBWy;

1.1.1.4
date	2017.01.11.10.39.40;	author joerg;	state Exp;
branches;
next	1.1.1.5;
commitid	CNnUNfII1jgNmxBz;

1.1.1.5
date	2017.08.01.19.34.21;	author joerg;	state Exp;
branches
	1.1.1.5.4.1;
next	1.1.1.6;
commitid	pMuDy65V0VicSx1A;

1.1.1.6
date	2019.11.13.22.20.14;	author joerg;	state dead;
branches;
next	;
commitid	QD8YATxuNG34YJKB;

1.1.1.1.2.1
date	2014.08.10.07.08.14;	author tls;	state Exp;
branches;
next	;
commitid	t01A1TLTYxkpGMLx;

1.1.1.1.4.1
date	2013.11.28.14.14.58;	author yamt;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.1.4.2
date	2014.05.22.16.18.56;	author yamt;	state Exp;
branches;
next	;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.2.4.1
date	2014.05.30.18.14.47;	author tls;	state dead;
branches;
next	1.1.1.2.4.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.2.4.2
date	2014.08.19.23.47.57;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.3.2.1
date	2017.03.20.06.52.59;	author pgoyette;	state Exp;
branches;
next	;
commitid	jjw7cAwgyKq7RfKz;

1.1.1.5.4.1
date	2020.04.13.07.47.28;	author martin;	state dead;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.1
log
@Initial revision
@
text
@// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix CHECK-NOEXC %s

struct A {
  A();
  ~A();
};

struct B { B(); ~B(); };

struct C { void *field; };

struct D { ~D(); };

// CHECK: @@__dso_handle = external unnamed_addr global i8
// CHECK: @@c = global %struct.C zeroinitializer, align 8

// It's okay if we ever implement the IR-generation optimization to remove this.
// CHECK: @@_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 x i8]* 

// PR6205: The casts should not require global initializers
// CHECK: @@_ZN6PR59741cE = external global %"struct.PR5974::C"
// CHECK: @@_ZN6PR59741aE = global %"struct.PR5974::A"* getelementptr inbounds (%"struct.PR5974::C"* @@_ZN6PR59741cE, i32 0, i32 0)
// CHECK: @@_ZN6PR59741bE = global %"struct.PR5974::B"* bitcast (i8* getelementptr (i8* bitcast (%"struct.PR5974::C"* @@_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::B"*), align 8

// CHECK: call void @@_ZN1AC1Ev(%struct.A* @@a)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @@_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @@a, i32 0, i32 0), i8* @@__dso_handle)
A a;

// CHECK: call void @@_ZN1BC1Ev(%struct.B* @@b)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.B*)* @@_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.B* @@b, i32 0, i32 0), i8* @@__dso_handle)
B b;

// PR6205: this should not require a global initializer
// CHECK-NOT: call void @@_ZN1CC1Ev(%struct.C* @@c)
C c;

// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.D*)* @@_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.D* @@d, i32 0, i32 0), i8* @@__dso_handle)
D d;

// <rdar://problem/7458115>
namespace test1 {
  int f();
  const int x = f();   // This has side-effects and gets emitted immediately.
  const int y = x - 1; // This gets deferred.
  const int z = ~y;    // This also gets deferred, but gets "undeferred" before y.
  int test() { return z; }
// CHECK-LABEL:      define i32 @@_ZN5test14testEv()

  // All of these initializers end up delayed, so we check them later.
}

// <rdar://problem/8246444>
namespace test2 {
  struct allocator { allocator(); ~allocator(); };
  struct A { A(const allocator &a = allocator()); ~A(); };

  A a;
// CHECK: call void @@_ZN5test29allocatorC1Ev(
// CHECK: invoke void @@_ZN5test21AC1ERKNS_9allocatorE(
// CHECK: call void @@_ZN5test29allocatorD1Ev(
// CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test21AD1Ev {{.*}} @@_ZN5test21aE
}

namespace test3 {
  // Tested at the beginning of the file.
  const char * const var = "string";
  extern const char * const var;

  const char *test() { return var; }
}

namespace test4 {
  struct A {
    A();
  };
  extern int foo();

  // This needs an initialization function and guard variables.
  // CHECK: load i8* bitcast (i64* @@_ZGVN5test41xE
  // CHECK: [[CALL:%.*]] = call i32 @@_ZN5test43fooEv
  // CHECK-NEXT: store i32 [[CALL]], i32* @@_ZN5test41xE
  // CHECK-NEXT: store i64 1, i64* @@_ZGVN5test41xE
  __attribute__((weak)) int x = foo();
}

namespace PR5974 {
  struct A { int a; };
  struct B { int b; };
  struct C : A, B { int c; };

  extern C c;

  // These should not require global initializers.
  A* a = &c;
  B* b = &c;
}

// PR9570: the indirect field shouldn't crash IR gen.
namespace test5 {
  static union {
    unsigned bar[4096] __attribute__((aligned(128)));
  };
}

namespace std { struct type_info; }

namespace test6 {
  struct A { virtual ~A(); };
  struct B : A {};
  extern A *p;

  // We must emit a dynamic initializer for 'q', because it could throw.
  B *const q = &dynamic_cast<B&>(*p);
  // CHECK: call void @@__cxa_bad_cast()
  // CHECK: store {{.*}} @@_ZN5test6L1qE

  // We don't need to emit 'r' at all, because it has internal linkage, is
  // unused, and its initialization has no side-effects.
  B *const r = dynamic_cast<B*>(p);
  // CHECK-NOT: call void @@__cxa_bad_cast()
  // CHECK-NOT: store {{.*}} @@_ZN5test6L1rE

  // This can throw, so we need to emit it.
  const std::type_info *const s = &typeid(*p);
  // CHECK: store {{.*}} @@_ZN5test6L1sE

  // This can't throw, so we don't.
  const std::type_info *const t = &typeid(p);
  // CHECK-NOT: @@_ZN5test6L1tE

  extern B *volatile v;
  // CHECK: store {{.*}} @@_ZN5test6L1wE
  B *const w = dynamic_cast<B*>(v);

  // CHECK: load volatile
  // CHECK: store {{.*}} @@_ZN5test6L1xE
  const int x = *(volatile int*)0x1234;

  namespace {
    int a = int();
    volatile int b = int();
    int c = a;
    int d = b;
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1aE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1cE
    // CHECK: load volatile {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1dE
  }
}

namespace test7 {
  struct A { A(); };
  struct B { ~B(); int n; };
  struct C { C() = default; C(const C&); int n; };
  struct D {};

  // CHECK: call void @@_ZN5test71AC1Ev({{.*}}@@_ZN5test7L1aE)
  const A a = A();

  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZN5test7L2b1E
  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZGRN5test72b2E
  // CHECK: call void @@_ZN5test71BD1Ev(
  // CHECK: store {{.*}} @@_ZN5test7L2b3E
  const B b1 = B();
  const B &b2 = B();
  const int b3 = B().n;

  // CHECK-NOT: @@_ZN5test7L2c1E
  // CHECK: @@_ZN5test7L2c2E
  // CHECK-NOT: @@_ZN5test7L2c3E
  // CHECK: @@_ZN5test7L2c4E
  const C c1 = C();
  const C c2 = static_cast<const C&>(C());
  const int c3 = C().n;
  const int c4 = C(C()).n;

  // CHECK-NOT: @@_ZN5test7L1dE
  const D d = D();

  // CHECK: store {{.*}} @@_ZN5test71eE
  int f(), e = f();
}


// At the end of the file, we check that y is initialized before z.

// CHECK:      define internal void [[TEST1_Z_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1yE
// CHECK-NEXT:   xor
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1zE
// CHECK:      define internal void [[TEST1_Y_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1xE
// CHECK-NEXT:   sub
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1yE

// CHECK: define internal void @@_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {
// CHECK:   call void [[TEST1_Y_INIT]]
// CHECK:   call void [[TEST1_Z_INIT]]

// rdar://problem/8090834: this should be nounwind
// CHECK-NOEXC: define internal void @@_GLOBAL__I_a() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {

// CHECK-NOEXC: attributes [[NUW]] = { nounwind }
@


1.1.1.1
log
@Import Clang 3.4rc1 r195771.
@
text
@@


1.1.1.1.2.1
log
@Rebase.
@
text
@d15 1
a15 1
// CHECK: @@__dso_handle = external global i8
d198 1
a198 1
// CHECK: define internal void @@_GLOBAL__sub_I_global_init.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
d203 1
a203 1
// CHECK-NOEXC: define internal void @@_GLOBAL__sub_I_global_init.cpp() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {
@


1.1.1.2
log
@Import Clang 3.5svn r209886.
@
text
@d15 1
a15 1
// CHECK: @@__dso_handle = external global i8
d198 1
a198 1
// CHECK: define internal void @@_GLOBAL__sub_I_global_init.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
d203 1
a203 1
// CHECK-NOEXC: define internal void @@_GLOBAL__sub_I_global_init.cpp() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {
@


1.1.1.3
log
@Import Clang 3.8.0rc3 r261930.
@
text
@a2 3
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm \
// RUN:     -momit-leaf-frame-pointer -mdisable-fp-elim %s -o - \
// RUN:   | FileCheck -check-prefix CHECK-FP %s
d19 1
a19 1
// CHECK: @@_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 x i8], [7 x i8]* 
d23 2
a24 2
// CHECK: @@_ZN6PR59741aE = global %"struct.PR5974::A"* getelementptr inbounds (%"struct.PR5974::C", %"struct.PR5974::C"* @@_ZN6PR59741cE, i32 0, i32 0)
// CHECK: @@_ZN6PR59741bE = global %"struct.PR5974::B"* bitcast (i8* getelementptr (i8, i8* bitcast (%"struct.PR5974::C"* @@_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::B"*), align 8
d27 1
a27 1
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @@_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A, %struct.A* @@a, i32 0, i32 0), i8* @@__dso_handle)
d31 1
a31 1
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.B*)* @@_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.B, %struct.B* @@b, i32 0, i32 0), i8* @@__dso_handle)
d38 1
a38 1
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.D*)* @@_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.D, %struct.D* @@d, i32 0, i32 0), i8* @@__dso_handle)
d80 1
a80 1
  // CHECK: load i8, i8* bitcast (i64* @@_ZGVN5test41xE
d190 1
a190 1
// CHECK:        load i32, i32* @@_ZN5test1L1yE
d194 1
a194 1
// CHECK:        load i32, i32* @@_ZN5test1L1xE
d198 1
a198 1
// CHECK: define internal void @@_GLOBAL__sub_I_global_init.cpp() #{{[0-9]+}} section "__TEXT,__StaticInit,regular,pure_instructions" {
d205 1
a205 5
// CHECK-NOEXC: attributes [[NUW]] = { nounwind{{.*}} }

// PR21811: attach the appropriate attribute to the global init function
// CHECK-FP: define internal void @@_GLOBAL__sub_I_global_init.cpp() [[NUX:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {
// CHECK-FP: attributes [[NUX]] = { nounwind {{.*}}"no-frame-pointer-elim-non-leaf"{{.*}} }
@


1.1.1.3.2.1
log
@Sync with HEAD
@
text
@d21 3
a173 2
  // CHECK: call void @@llvm.memset{{.*}} @@_ZN5test7L2c1E
  // CHECK-NOT: @@_ZN5test7L2c1E
d208 1
a208 1
// CHECK-NOEXC: attributes [[NUW]] = { noinline nounwind{{.*}} }
d212 1
a212 1
// CHECK-FP: attributes [[NUX]] = { noinline nounwind {{.*}}"no-frame-pointer-elim-non-leaf"{{.*}} }
@


1.1.1.4
log
@Import Clang pre-4.0.0 r291444.
@
text
@d21 3
a173 2
  // CHECK: call void @@llvm.memset{{.*}} @@_ZN5test7L2c1E
  // CHECK-NOT: @@_ZN5test7L2c1E
d208 1
a208 1
// CHECK-NOEXC: attributes [[NUW]] = { noinline nounwind{{.*}} }
d212 1
a212 1
// CHECK-FP: attributes [[NUX]] = { noinline nounwind {{.*}}"no-frame-pointer-elim-non-leaf"{{.*}} }
@


1.1.1.5
log
@Import clang r309604 from branches/release_50
@
text
@d18 1
a18 1
// CHECK: @@__dso_handle = external hidden global i8
@


1.1.1.5.4.1
log
@Mostly merge changes from HEAD upto 20200411
@
text
@@


1.1.1.6
log
@Mark old LLVM instance as dead.
@
text
@@


1.1.1.2.4.1
log
@file global-init.cpp was added on branch tls-maxphys on 2014-08-19 23:47:57 +0000
@
text
@d1 205
@


1.1.1.2.4.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 205
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix CHECK-NOEXC %s

struct A {
  A();
  ~A();
};

struct B { B(); ~B(); };

struct C { void *field; };

struct D { ~D(); };

// CHECK: @@__dso_handle = external global i8
// CHECK: @@c = global %struct.C zeroinitializer, align 8

// It's okay if we ever implement the IR-generation optimization to remove this.
// CHECK: @@_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 x i8]* 

// PR6205: The casts should not require global initializers
// CHECK: @@_ZN6PR59741cE = external global %"struct.PR5974::C"
// CHECK: @@_ZN6PR59741aE = global %"struct.PR5974::A"* getelementptr inbounds (%"struct.PR5974::C"* @@_ZN6PR59741cE, i32 0, i32 0)
// CHECK: @@_ZN6PR59741bE = global %"struct.PR5974::B"* bitcast (i8* getelementptr (i8* bitcast (%"struct.PR5974::C"* @@_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::B"*), align 8

// CHECK: call void @@_ZN1AC1Ev(%struct.A* @@a)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @@_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @@a, i32 0, i32 0), i8* @@__dso_handle)
A a;

// CHECK: call void @@_ZN1BC1Ev(%struct.B* @@b)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.B*)* @@_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.B* @@b, i32 0, i32 0), i8* @@__dso_handle)
B b;

// PR6205: this should not require a global initializer
// CHECK-NOT: call void @@_ZN1CC1Ev(%struct.C* @@c)
C c;

// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.D*)* @@_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.D* @@d, i32 0, i32 0), i8* @@__dso_handle)
D d;

// <rdar://problem/7458115>
namespace test1 {
  int f();
  const int x = f();   // This has side-effects and gets emitted immediately.
  const int y = x - 1; // This gets deferred.
  const int z = ~y;    // This also gets deferred, but gets "undeferred" before y.
  int test() { return z; }
// CHECK-LABEL:      define i32 @@_ZN5test14testEv()

  // All of these initializers end up delayed, so we check them later.
}

// <rdar://problem/8246444>
namespace test2 {
  struct allocator { allocator(); ~allocator(); };
  struct A { A(const allocator &a = allocator()); ~A(); };

  A a;
// CHECK: call void @@_ZN5test29allocatorC1Ev(
// CHECK: invoke void @@_ZN5test21AC1ERKNS_9allocatorE(
// CHECK: call void @@_ZN5test29allocatorD1Ev(
// CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test21AD1Ev {{.*}} @@_ZN5test21aE
}

namespace test3 {
  // Tested at the beginning of the file.
  const char * const var = "string";
  extern const char * const var;

  const char *test() { return var; }
}

namespace test4 {
  struct A {
    A();
  };
  extern int foo();

  // This needs an initialization function and guard variables.
  // CHECK: load i8* bitcast (i64* @@_ZGVN5test41xE
  // CHECK: [[CALL:%.*]] = call i32 @@_ZN5test43fooEv
  // CHECK-NEXT: store i32 [[CALL]], i32* @@_ZN5test41xE
  // CHECK-NEXT: store i64 1, i64* @@_ZGVN5test41xE
  __attribute__((weak)) int x = foo();
}

namespace PR5974 {
  struct A { int a; };
  struct B { int b; };
  struct C : A, B { int c; };

  extern C c;

  // These should not require global initializers.
  A* a = &c;
  B* b = &c;
}

// PR9570: the indirect field shouldn't crash IR gen.
namespace test5 {
  static union {
    unsigned bar[4096] __attribute__((aligned(128)));
  };
}

namespace std { struct type_info; }

namespace test6 {
  struct A { virtual ~A(); };
  struct B : A {};
  extern A *p;

  // We must emit a dynamic initializer for 'q', because it could throw.
  B *const q = &dynamic_cast<B&>(*p);
  // CHECK: call void @@__cxa_bad_cast()
  // CHECK: store {{.*}} @@_ZN5test6L1qE

  // We don't need to emit 'r' at all, because it has internal linkage, is
  // unused, and its initialization has no side-effects.
  B *const r = dynamic_cast<B*>(p);
  // CHECK-NOT: call void @@__cxa_bad_cast()
  // CHECK-NOT: store {{.*}} @@_ZN5test6L1rE

  // This can throw, so we need to emit it.
  const std::type_info *const s = &typeid(*p);
  // CHECK: store {{.*}} @@_ZN5test6L1sE

  // This can't throw, so we don't.
  const std::type_info *const t = &typeid(p);
  // CHECK-NOT: @@_ZN5test6L1tE

  extern B *volatile v;
  // CHECK: store {{.*}} @@_ZN5test6L1wE
  B *const w = dynamic_cast<B*>(v);

  // CHECK: load volatile
  // CHECK: store {{.*}} @@_ZN5test6L1xE
  const int x = *(volatile int*)0x1234;

  namespace {
    int a = int();
    volatile int b = int();
    int c = a;
    int d = b;
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1aE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1cE
    // CHECK: load volatile {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1dE
  }
}

namespace test7 {
  struct A { A(); };
  struct B { ~B(); int n; };
  struct C { C() = default; C(const C&); int n; };
  struct D {};

  // CHECK: call void @@_ZN5test71AC1Ev({{.*}}@@_ZN5test7L1aE)
  const A a = A();

  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZN5test7L2b1E
  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZGRN5test72b2E
  // CHECK: call void @@_ZN5test71BD1Ev(
  // CHECK: store {{.*}} @@_ZN5test7L2b3E
  const B b1 = B();
  const B &b2 = B();
  const int b3 = B().n;

  // CHECK-NOT: @@_ZN5test7L2c1E
  // CHECK: @@_ZN5test7L2c2E
  // CHECK-NOT: @@_ZN5test7L2c3E
  // CHECK: @@_ZN5test7L2c4E
  const C c1 = C();
  const C c2 = static_cast<const C&>(C());
  const int c3 = C().n;
  const int c4 = C(C()).n;

  // CHECK-NOT: @@_ZN5test7L1dE
  const D d = D();

  // CHECK: store {{.*}} @@_ZN5test71eE
  int f(), e = f();
}


// At the end of the file, we check that y is initialized before z.

// CHECK:      define internal void [[TEST1_Z_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1yE
// CHECK-NEXT:   xor
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1zE
// CHECK:      define internal void [[TEST1_Y_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1xE
// CHECK-NEXT:   sub
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1yE

// CHECK: define internal void @@_GLOBAL__sub_I_global_init.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
// CHECK:   call void [[TEST1_Y_INIT]]
// CHECK:   call void [[TEST1_Z_INIT]]

// rdar://problem/8090834: this should be nounwind
// CHECK-NOEXC: define internal void @@_GLOBAL__sub_I_global_init.cpp() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {

// CHECK-NOEXC: attributes [[NUW]] = { nounwind }
@


1.1.1.1.4.1
log
@file global-init.cpp was added on branch yamt-pagecache on 2014-05-22 16:18:56 +0000
@
text
@d1 205
@


1.1.1.1.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 205
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s
// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix CHECK-NOEXC %s

struct A {
  A();
  ~A();
};

struct B { B(); ~B(); };

struct C { void *field; };

struct D { ~D(); };

// CHECK: @@__dso_handle = external unnamed_addr global i8
// CHECK: @@c = global %struct.C zeroinitializer, align 8

// It's okay if we ever implement the IR-generation optimization to remove this.
// CHECK: @@_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 x i8]* 

// PR6205: The casts should not require global initializers
// CHECK: @@_ZN6PR59741cE = external global %"struct.PR5974::C"
// CHECK: @@_ZN6PR59741aE = global %"struct.PR5974::A"* getelementptr inbounds (%"struct.PR5974::C"* @@_ZN6PR59741cE, i32 0, i32 0)
// CHECK: @@_ZN6PR59741bE = global %"struct.PR5974::B"* bitcast (i8* getelementptr (i8* bitcast (%"struct.PR5974::C"* @@_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::B"*), align 8

// CHECK: call void @@_ZN1AC1Ev(%struct.A* @@a)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @@_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @@a, i32 0, i32 0), i8* @@__dso_handle)
A a;

// CHECK: call void @@_ZN1BC1Ev(%struct.B* @@b)
// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.B*)* @@_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.B* @@b, i32 0, i32 0), i8* @@__dso_handle)
B b;

// PR6205: this should not require a global initializer
// CHECK-NOT: call void @@_ZN1CC1Ev(%struct.C* @@c)
C c;

// CHECK: call i32 @@__cxa_atexit(void (i8*)* bitcast (void (%struct.D*)* @@_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.D* @@d, i32 0, i32 0), i8* @@__dso_handle)
D d;

// <rdar://problem/7458115>
namespace test1 {
  int f();
  const int x = f();   // This has side-effects and gets emitted immediately.
  const int y = x - 1; // This gets deferred.
  const int z = ~y;    // This also gets deferred, but gets "undeferred" before y.
  int test() { return z; }
// CHECK-LABEL:      define i32 @@_ZN5test14testEv()

  // All of these initializers end up delayed, so we check them later.
}

// <rdar://problem/8246444>
namespace test2 {
  struct allocator { allocator(); ~allocator(); };
  struct A { A(const allocator &a = allocator()); ~A(); };

  A a;
// CHECK: call void @@_ZN5test29allocatorC1Ev(
// CHECK: invoke void @@_ZN5test21AC1ERKNS_9allocatorE(
// CHECK: call void @@_ZN5test29allocatorD1Ev(
// CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test21AD1Ev {{.*}} @@_ZN5test21aE
}

namespace test3 {
  // Tested at the beginning of the file.
  const char * const var = "string";
  extern const char * const var;

  const char *test() { return var; }
}

namespace test4 {
  struct A {
    A();
  };
  extern int foo();

  // This needs an initialization function and guard variables.
  // CHECK: load i8* bitcast (i64* @@_ZGVN5test41xE
  // CHECK: [[CALL:%.*]] = call i32 @@_ZN5test43fooEv
  // CHECK-NEXT: store i32 [[CALL]], i32* @@_ZN5test41xE
  // CHECK-NEXT: store i64 1, i64* @@_ZGVN5test41xE
  __attribute__((weak)) int x = foo();
}

namespace PR5974 {
  struct A { int a; };
  struct B { int b; };
  struct C : A, B { int c; };

  extern C c;

  // These should not require global initializers.
  A* a = &c;
  B* b = &c;
}

// PR9570: the indirect field shouldn't crash IR gen.
namespace test5 {
  static union {
    unsigned bar[4096] __attribute__((aligned(128)));
  };
}

namespace std { struct type_info; }

namespace test6 {
  struct A { virtual ~A(); };
  struct B : A {};
  extern A *p;

  // We must emit a dynamic initializer for 'q', because it could throw.
  B *const q = &dynamic_cast<B&>(*p);
  // CHECK: call void @@__cxa_bad_cast()
  // CHECK: store {{.*}} @@_ZN5test6L1qE

  // We don't need to emit 'r' at all, because it has internal linkage, is
  // unused, and its initialization has no side-effects.
  B *const r = dynamic_cast<B*>(p);
  // CHECK-NOT: call void @@__cxa_bad_cast()
  // CHECK-NOT: store {{.*}} @@_ZN5test6L1rE

  // This can throw, so we need to emit it.
  const std::type_info *const s = &typeid(*p);
  // CHECK: store {{.*}} @@_ZN5test6L1sE

  // This can't throw, so we don't.
  const std::type_info *const t = &typeid(p);
  // CHECK-NOT: @@_ZN5test6L1tE

  extern B *volatile v;
  // CHECK: store {{.*}} @@_ZN5test6L1wE
  B *const w = dynamic_cast<B*>(v);

  // CHECK: load volatile
  // CHECK: store {{.*}} @@_ZN5test6L1xE
  const int x = *(volatile int*)0x1234;

  namespace {
    int a = int();
    volatile int b = int();
    int c = a;
    int d = b;
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1aE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK-NOT: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1cE
    // CHECK: load volatile {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1bE
    // CHECK: store {{.*}} @@_ZN5test6{{[A-Za-z0-9_]*}}1dE
  }
}

namespace test7 {
  struct A { A(); };
  struct B { ~B(); int n; };
  struct C { C() = default; C(const C&); int n; };
  struct D {};

  // CHECK: call void @@_ZN5test71AC1Ev({{.*}}@@_ZN5test7L1aE)
  const A a = A();

  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZN5test7L2b1E
  // CHECK: call i32 @@__cxa_atexit({{.*}} @@_ZN5test71BD1Ev{{.*}} @@_ZGRN5test72b2E
  // CHECK: call void @@_ZN5test71BD1Ev(
  // CHECK: store {{.*}} @@_ZN5test7L2b3E
  const B b1 = B();
  const B &b2 = B();
  const int b3 = B().n;

  // CHECK-NOT: @@_ZN5test7L2c1E
  // CHECK: @@_ZN5test7L2c2E
  // CHECK-NOT: @@_ZN5test7L2c3E
  // CHECK: @@_ZN5test7L2c4E
  const C c1 = C();
  const C c2 = static_cast<const C&>(C());
  const int c3 = C().n;
  const int c4 = C(C()).n;

  // CHECK-NOT: @@_ZN5test7L1dE
  const D d = D();

  // CHECK: store {{.*}} @@_ZN5test71eE
  int f(), e = f();
}


// At the end of the file, we check that y is initialized before z.

// CHECK:      define internal void [[TEST1_Z_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1yE
// CHECK-NEXT:   xor
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1zE
// CHECK:      define internal void [[TEST1_Y_INIT:@@.*]]()
// CHECK:        load i32* @@_ZN5test1L1xE
// CHECK-NEXT:   sub
// CHECK-NEXT:   store i32 {{.*}}, i32* @@_ZN5test1L1yE

// CHECK: define internal void @@_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {
// CHECK:   call void [[TEST1_Y_INIT]]
// CHECK:   call void [[TEST1_Z_INIT]]

// rdar://problem/8090834: this should be nounwind
// CHECK-NOEXC: define internal void @@_GLOBAL__I_a() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {

// CHECK-NOEXC: attributes [[NUW]] = { nounwind }
@


