blob: dd9ed61434e21a14e0e82fe6b9cbb67ce4a65310 [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
Rafael Espindola6deecb02010-06-04 23:15:27 +00005// CHECK: @_ZZN5test16getvarEiE3var = 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() {
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000015 // CHECK: call i32 @__cxa_guard_acquire
16 // CHECK: call void @_ZN1AC1Ev
Anders Carlssonc7974ca2009-12-10 01:05:11 +000017 // 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 +000018 // CHECK: call void @__cxa_guard_release
Anders Carlsson3b2e16b2009-08-08 21:45:14 +000019 static A a;
20}
21
Anders Carlssonc7974ca2009-12-10 01:05:11 +000022void g() {
Nuno Lopesfc284482009-12-16 16:59:22 +000023 // CHECK: call noalias i8* @_Znwm(i64 1)
Anders Carlssonc7974ca2009-12-10 01:05:11 +000024 // CHECK: call void @_ZN1AC1Ev(
25 static A& a = *new A;
26}
Anders Carlsson071c8102010-01-26 04:02:23 +000027
28int a();
29void h() {
30 static const int i = a();
31}
Anders Carlssonf6b89a12010-02-07 02:03:08 +000032
33inline void h2() {
34 static int i = a();
35}
36
37void h3() {
38 h2();
39}
John McCalle65ce962010-05-03 21:39:56 +000040
41// PR6980: this shouldn't crash
42namespace test0 {
43 struct A { A(); };
44 __attribute__((noreturn)) int throw_exception();
45
46 void test() {
47 throw_exception();
48 static A r;
49 }
50}
John McCall8b242332010-05-25 04:30:21 +000051
52namespace test1 {
53 // CHECK: define internal i32 @_ZN5test16getvarEi(
54 static inline int getvar(int index) {
55 static const int var[] = { 1, 0, 2, 4 };
56 return var[index];
57 }
58
59 void test() { (void) getvar(2); }
60}