blob: b2857ff41714d6aac22306fdccf97c672105bd5d [file] [log] [blame]
Anders Carlsson6774b1f2011-02-28 00:40:07 +00001// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin10 -emit-llvm %s -o - > %t
Tim Northover19ae1172013-08-12 12:51:05 +00002// RUN: FileCheck %s -check-prefix=CHECK-1 < %t
3// RUN: FileCheck %s -check-prefix=CHECK-2 < %t
John McCall4fa53422009-10-01 00:25:31 +00004
Anders Carlssond6b21e42010-01-26 06:15:16 +00005int f();
6
John McCall4fa53422009-10-01 00:25:31 +00007namespace {
John McCall8823c652010-08-13 08:35:10 +00008 // CHECK-1: @_ZN12_GLOBAL__N_11bE = internal global i32 0
Richard Smithdf963a32017-09-22 22:21:44 +00009 // CHECK-1: @_ZN12_GLOBAL__N_11cE = internal global i32 0
10 // CHECK-1: @_ZN12_GLOBAL__N_12c2E = internal global i32 0
John McCall8823c652010-08-13 08:35:10 +000011 // CHECK-1: @_ZN12_GLOBAL__N_11D1dE = internal global i32 0
12 // CHECK-1: @_ZN12_GLOBAL__N_11aE = internal global i32 0
John McCall4fa53422009-10-01 00:25:31 +000013 int a = 0;
14
Anders Carlssond6b21e42010-01-26 06:15:16 +000015 int b = f();
16
17 static int c = f();
18
Richard Smithdf963a32017-09-22 22:21:44 +000019 // Note, we can't use an 'L' mangling for c or c2 (like GCC does) based on
20 // the 'static' specifier, because the variable can be redeclared without it.
21 extern int c2;
22 int g() { return c2; }
23 static int c2 = f();
24
Anders Carlssond6b21e42010-01-26 06:15:16 +000025 class D {
26 static int d;
27 };
28
29 int D::d = f();
30
Douglas Gregorae498b32010-05-06 22:18:21 +000031 // Check for generation of a VTT with internal linkage
John McCall8823c652010-08-13 08:35:10 +000032 // CHECK-1: @_ZTSN12_GLOBAL__N_11X1EE = internal constant
Douglas Gregorae498b32010-05-06 22:18:21 +000033 struct X {
34 struct EBase { };
35 struct E : public virtual EBase { virtual ~E() {} };
36 };
37
Stephen Lin43622612013-08-15 06:47:53 +000038 // CHECK-1-LABEL: define internal i32 @_ZN12_GLOBAL__N_13fooEv()
John McCall4fa53422009-10-01 00:25:31 +000039 int foo() {
40 return 32;
41 }
42
Stephen Lin43622612013-08-15 06:47:53 +000043 // CHECK-1-LABEL: define internal i32 @_ZN12_GLOBAL__N_11A3fooEv()
John McCall4fa53422009-10-01 00:25:31 +000044 namespace A {
45 int foo() {
46 return 45;
47 }
48 }
49}
50
51int concrete() {
52 return a + foo() + A::foo();
53}
Douglas Gregorae498b32010-05-06 22:18:21 +000054
55void test_XE() { throw X::E(); }
John McCall8823c652010-08-13 08:35:10 +000056
57// Miscompile on llvmc plugins.
58namespace test2 {
59 struct A {
60 template <class T> struct B {
61 static void foo() {}
62 };
63 };
64 namespace {
65 struct C;
66 }
67
Stephen Lin43622612013-08-15 06:47:53 +000068 // CHECK-2-LABEL: define void @_ZN5test24testEv()
John McCall8823c652010-08-13 08:35:10 +000069 // CHECK-2: call void @_ZN5test21A1BINS_12_GLOBAL__N_11CEE3fooEv()
70 void test() {
71 A::B<C>::foo();
72 }
73
Stephen Lin43622612013-08-15 06:47:53 +000074 // CHECK-2-LABEL: define internal void @_ZN5test21A1BINS_12_GLOBAL__N_11CEE3fooEv()
John McCall8823c652010-08-13 08:35:10 +000075}
Enea Zaffanellacf51a8a2013-05-16 11:27:56 +000076
77namespace {
78
79int bar() {
80 extern int a;
81 return a;
82}
83
84} // namespace