summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX
diff options
context:
space:
mode:
Diffstat (limited to 'test/CodeGenCXX')
-rw-r--r--test/CodeGenCXX/__null.cpp9
-rw-r--r--test/CodeGenCXX/const-init.cpp11
-rw-r--r--test/CodeGenCXX/explicit-instantiation.cpp11
-rw-r--r--test/CodeGenCXX/expr.cpp5
-rw-r--r--test/CodeGenCXX/extern-c.cpp13
-rw-r--r--test/CodeGenCXX/mangle.cpp87
-rw-r--r--test/CodeGenCXX/member-functions.cpp63
-rw-r--r--test/CodeGenCXX/new.cpp56
-rw-r--r--test/CodeGenCXX/reference-field.cpp6
-rw-r--r--test/CodeGenCXX/references.cpp89
10 files changed, 350 insertions, 0 deletions
diff --git a/test/CodeGenCXX/__null.cpp b/test/CodeGenCXX/__null.cpp
new file mode 100644
index 0000000..476b0ad
--- /dev/null
+++ b/test/CodeGenCXX/__null.cpp
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -emit-llvm -o %t
+
+int* a = __null;
+int b = __null;
+
+void f() {
+ int* c = __null;
+ int d = __null;
+}
diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp
new file mode 100644
index 0000000..427ba53
--- /dev/null
+++ b/test/CodeGenCXX/const-init.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-cc -verify -emit-llvm -o %t %s
+
+int a = 10;
+int &ar = a;
+
+void f();
+void (&fr)() = f;
+
+struct S { int& a; };
+S s = { a };
+
diff --git a/test/CodeGenCXX/explicit-instantiation.cpp b/test/CodeGenCXX/explicit-instantiation.cpp
new file mode 100644
index 0000000..38966aa
--- /dev/null
+++ b/test/CodeGenCXX/explicit-instantiation.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-cc -emit-llvm -femit-all-decls -o %t %s &&
+// RUN: grep "_ZNK4plusIillEclERKiRKl" %t | count 1
+
+template<typename T, typename U, typename Result>
+struct plus {
+ Result operator()(const T& t, const U& u) const {
+ return t + u;
+ }
+};
+
+template struct plus<int, long, long>;
diff --git a/test/CodeGenCXX/expr.cpp b/test/CodeGenCXX/expr.cpp
new file mode 100644
index 0000000..ae5b0e6
--- /dev/null
+++ b/test/CodeGenCXX/expr.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-cc -emit-llvm -x c++ < %s
+
+void f(int x) {
+ if (x != 0) return;
+}
diff --git a/test/CodeGenCXX/extern-c.cpp b/test/CodeGenCXX/extern-c.cpp
new file mode 100644
index 0000000..6353293
--- /dev/null
+++ b/test/CodeGenCXX/extern-c.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-cc -emit-llvm %s -o %t &&
+namespace foo {
+
+// RUN: not grep "@a = global i32" %t &&
+extern "C" int a;
+
+// RUN: not grep "@_ZN3foo1bE = global i32" %t &&
+extern int b;
+
+// RUN: grep "@_ZN3foo1cE = global i32" %t | count 1
+int c = 5;
+
+}
diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp
new file mode 100644
index 0000000..ef36a8b
--- /dev/null
+++ b/test/CodeGenCXX/mangle.cpp
@@ -0,0 +1,87 @@
+// RUN: clang-cc -emit-llvm %s -o %t -triple=x86_64-apple-darwin9 &&
+
+// FIXME: This test is intentionally trivial, because we can't yet
+// CodeGen anything real in C++.
+struct X { };
+struct Y { };
+
+// RUN: grep _ZplRK1YRA100_P1X %t | count 1 &&
+bool operator+(const Y&, X* (&xs)[100]) { return false; }
+
+// RUN: grep _Z1f1s %t | count 1 &&
+typedef struct { int a; } s;
+void f(s) { }
+
+// RUN: grep _Z1f1e %t| count 1 &&
+typedef enum { foo } e;
+void f(e) { }
+
+// RUN: grep _Z1f1u %t | count 1 &&
+typedef union { int a; } u;
+void f(u) { }
+
+// RUN: grep _Z1f1x %t | count 1 &&
+typedef struct { int a; } x,y;
+void f(y) { }
+
+// RUN: grep _Z1fv %t | count 1 &&
+void f() { }
+
+// RUN: grep _ZN1N1fEv %t | count 1 &&
+namespace N { void f() { } }
+
+// RUN: grep _ZN1N1N1fEv %t | count 1 &&
+namespace N { namespace N { void f() { } } }
+
+// RUN: grep unmangled_function %t | count 1 &&
+extern "C" { namespace N { void unmangled_function() { } } }
+
+// RUN: grep unmangled_variable %t | count 1 &&
+extern "C" { namespace N { int unmangled_variable = 10; } }
+
+// RUN: grep _ZN1N1iE %t | count 1 &&
+namespace N { int i; }
+
+// RUN: grep _ZZN1N1fEiiE1b %t | count 2 &&
+namespace N { int f(int, int) { static int b; return b; } }
+
+// RUN: grep "_ZZN1N1gEvE1a =" %t | count 1 &&
+// RUN: grep "_ZGVZN1N1gEvE1a =" %t | count 1 &&
+namespace N { int h(); void g() { static int a = h(); } }
+
+// RUN: grep "_Z1fno" %t | count 1 &&
+void f(__int128_t, __uint128_t) { }
+
+template <typename T> struct S1 {};
+
+// RUN: grep "_Z1f2S1IiE" %t | count 1 &&
+void f(S1<int>) {}
+
+// RUN: grep "_Z1f2S1IdE" %t | count 1 &&
+void f(S1<double>) {}
+
+template <int N> struct S2 {};
+// RUN: grep "_Z1f2S2ILi100EE" %t | count 1 &&
+void f(S2<100>) {}
+
+// RUN: grep "_Z1f2S2ILin100EE" %t | count 1 &&
+void f(S2<-100>) {}
+
+template <bool B> struct S3 {};
+
+// RUN: grep "_Z1f2S3ILb1EE" %t | count 1 &&
+void f(S3<true>) {}
+
+// RUN: grep "_Z1f2S3ILb0EE" %t | count 1 &&
+void f(S3<false>) {}
+
+// RUN: grep "_Z2f22S3ILb1EE" %t | count 1 &&
+void f2(S3<100>) {}
+
+struct S;
+
+// RUN: grep "_Z1fM1SKFvvE" %t | count 1 &&
+void f(void (S::*)() const) {}
+
+// RUN: grep "_Z1fM1SFvvE" %t | count 1
+void f(void (S::*)()) {}
diff --git a/test/CodeGenCXX/member-functions.cpp b/test/CodeGenCXX/member-functions.cpp
new file mode 100644
index 0000000..8ada907
--- /dev/null
+++ b/test/CodeGenCXX/member-functions.cpp
@@ -0,0 +1,63 @@
+// RUN: clang-cc -emit-llvm %s -triple x86_64-apple-darwin9 -o %t &&
+struct C {
+ void f();
+ void g(int, ...);
+};
+
+// RUN: grep "define void @_ZN1C1fEv" %t | count 1 &&
+void C::f() {
+}
+
+void test1() {
+ C c;
+
+// RUN: grep "call void @_ZN1C1fEv" %t | count 1 &&
+ c.f();
+
+// RUN: grep "call void (.struct.C\*, i32, ...)\* @_ZN1C1gEiz" %t | count 1 &&
+ c.g(1, 2, 3);
+}
+
+
+struct S {
+ // RUN: grep "define linkonce_odr void @_ZN1SC1Ev" %t &&
+ inline S() { }
+ // RUN: grep "define linkonce_odr void @_ZN1SC1Ev" %t &&
+ inline ~S() { }
+
+
+ // RUN: grep "define linkonce_odr void @_ZN1S9f_inline1Ev" %t &&
+ void f_inline1() { }
+ // RUN: grep "define linkonce_odr void @_ZN1S9f_inline2Ev" %t &&
+ inline void f_inline2() { }
+
+ // RUN: grep "define linkonce_odr void @_ZN1S1gEv" %t &&
+ static void g() { }
+
+ static void f();
+};
+
+// RUN: grep "define void @_ZN1S1fEv" %t &&
+void S::f() {
+}
+
+void test2() {
+ S s;
+
+ s.f_inline1();
+ s.f_inline2();
+
+ S::g();
+
+}
+
+struct T {
+ T operator+(const T&);
+};
+
+void test3() {
+ T t1, t2;
+
+ // RUN: grep "call void @_ZN1TpsERK1T" %t
+ T result = t1 + t2;
+}
diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp
new file mode 100644
index 0000000..480bbce
--- /dev/null
+++ b/test/CodeGenCXX/new.cpp
@@ -0,0 +1,56 @@
+// RUN: clang-cc %s -emit-llvm -o %t &&
+
+void t1() {
+ int* a = new int;
+}
+
+// Placement.
+void* operator new(unsigned long, void*) throw();
+
+void t2(int* a) {
+ int* b = new (a) int;
+}
+
+struct S {
+ int a;
+};
+
+// POD types.
+void t3() {
+ int *a = new int(10);
+ _Complex int* b = new _Complex int(10i);
+
+ S s;
+ s.a = 10;
+ S *sp = new S(s);
+}
+
+// Non-POD
+struct T {
+ T();
+ int a;
+};
+
+void t4() {
+ // RUN: grep "call void @_ZN1TC1Ev" %t | count 1 &&
+ T *t = new T;
+}
+
+struct T2 {
+ int a;
+ T2(int, int);
+};
+
+void t5() {
+ // RUN: grep "call void @_ZN2T2C1Eii" %t | count 1
+ T2 *t2 = new T2(10, 10);
+}
+
+int *t6() {
+ // Null check.
+ return new (0) int(10);
+}
+
+void t7() {
+ new int();
+}
diff --git a/test/CodeGenCXX/reference-field.cpp b/test/CodeGenCXX/reference-field.cpp
new file mode 100644
index 0000000..88d4c1f
--- /dev/null
+++ b/test/CodeGenCXX/reference-field.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-cc -emit-llvm -o - %s -O2 | grep "@_Z1bv"
+
+// Make sure the call to b() doesn't get optimized out.
+extern struct x {char& x,y;}y;
+int b();
+int a() { if (!&y.x) b(); }
diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp
new file mode 100644
index 0000000..8e19356
--- /dev/null
+++ b/test/CodeGenCXX/references.cpp
@@ -0,0 +1,89 @@
+// RUN: clang-cc -verify -emit-llvm -o %t %s
+
+void t1() {
+ extern int& a;
+ int b = a;
+}
+
+void t2(int& a) {
+ int b = a;
+}
+
+int g;
+int& gr = g;
+int& grr = gr;
+void t3() {
+ int b = gr;
+}
+
+// Test reference binding.
+
+struct C { int a; };
+
+void f(const bool&);
+void f(const int&);
+void f(const _Complex int&);
+void f(const C&);
+
+C aggregate_return();
+
+bool& bool_reference_return();
+int& int_reference_return();
+_Complex int& complex_int_reference_return();
+C& aggregate_reference_return();
+
+void test_bool() {
+ bool a = true;
+ f(a);
+
+ f(true);
+
+ bool_reference_return() = true;
+ a = bool_reference_return();
+}
+
+void test_scalar() {
+ int a = 10;
+ f(a);
+
+ struct { int bitfield : 3; } s = { 3 };
+ f(s.bitfield);
+
+ f(10);
+
+ __attribute((vector_size(16))) typedef int vec4;
+ f((vec4){1,2,3,4}[0]);
+
+ int_reference_return() = 10;
+ a = int_reference_return();
+}
+
+void test_complex() {
+ _Complex int a = 10i;
+ f(a);
+
+ f(10i);
+
+ complex_int_reference_return() = 10i;
+ a = complex_int_reference_return();
+}
+
+void test_aggregate() {
+ C c;
+ f(c);
+
+ f(aggregate_return());
+ aggregate_reference_return().a = 10;
+
+ c = aggregate_reference_return();
+}
+
+int& reference_return() {
+ return g;
+}
+
+int reference_decl() {
+ int& a = g;
+ const int& b = 1;
+ return a+b;
+}
OpenPOWER on IntegriCloud