blob: 9e2673cc967ddade936c13b0d4fcd3e522be3bcb [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Anders Carlsson071c8102010-01-26 04:02:23 +00002
3// CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
Anders Carlssonf6b89a12010-02-07 02:03:08 +00004
John McCall78951942011-03-22 06:58:49 +00005// CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
John McCall8b242332010-05-25 04:30:21 +00006// CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0
7// CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0
Anders Carlssonf6b89a12010-02-07 02:03:08 +00008
Anders Carlsson3b2e16b2009-08-08 21:45:14 +00009struct A {
10 A();
11 ~A();
12};
13
14void f() {
Eli Friedmaneb43f4a2011-09-13 22:21:56 +000015 // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000016 // CHECK: call i32 @__cxa_guard_acquire
17 // CHECK: call void @_ZN1AC1Ev
Anders Carlssonc7974ca2009-12-10 01:05:11 +000018 // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @_ZZ1fvE1a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
John McCall5cd91b52010-09-08 01:44:27 +000019 // CHECK: call void @__cxa_guard_release
Anders Carlsson3b2e16b2009-08-08 21:45:14 +000020 static A a;
21}
22
Anders Carlssonc7974ca2009-12-10 01:05:11 +000023void g() {
Nuno Lopesfc284482009-12-16 16:59:22 +000024 // CHECK: call noalias i8* @_Znwm(i64 1)
Anders Carlssonc7974ca2009-12-10 01:05:11 +000025 // CHECK: call void @_ZN1AC1Ev(
26 static A& a = *new A;
27}
Anders Carlsson071c8102010-01-26 04:02:23 +000028
29int a();
30void h() {
31 static const int i = a();
32}
Anders Carlssonf6b89a12010-02-07 02:03:08 +000033
34inline void h2() {
35 static int i = a();
36}
37
38void h3() {
39 h2();
40}
John McCalle65ce962010-05-03 21:39:56 +000041
42// PR6980: this shouldn't crash
43namespace test0 {
44 struct A { A(); };
45 __attribute__((noreturn)) int throw_exception();
46
47 void test() {
48 throw_exception();
49 static A r;
50 }
51}
John McCall8b242332010-05-25 04:30:21 +000052
53namespace test1 {
John McCall78951942011-03-22 06:58:49 +000054 // CHECK: define internal i32 @_ZN5test1L6getvarEi(
John McCall8b242332010-05-25 04:30:21 +000055 static inline int getvar(int index) {
56 static const int var[] = { 1, 0, 2, 4 };
57 return var[index];
58 }
59
60 void test() { (void) getvar(2); }
61}