blob: f68b2206f209d4adfc119f7faf7afeb0b6925560 [file] [log] [blame]
Sebastian Pop9ec60df2012-01-20 22:01:23 +00001// RUN: %clang -target le32-unknown-nacl -ccc-clang-archs le32 -ccc-echo %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO
2// RUN: %clang -target le32-unknown-nacl -ccc-clang-archs le32 %s -emit-llvm -S -c -o - | FileCheck %s
3// RUN: %clang -target le32-unknown-nacl -ccc-clang-archs le32 %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS
Ivan Krasinef05abd2011-08-24 20:22:22 +00004
Chandler Carruth5aa5a812011-08-31 18:39:20 +00005// ECHO: {{.*}} -cc1 {{.*}}le32-unknown-nacl.c
Ivan Krasinef05abd2011-08-24 20:22:22 +00006
7// Check platform defines
Ivan Krasinf619cdc2011-08-29 22:39:12 +00008#include <stdarg.h>
Ivan Krasinef05abd2011-08-24 20:22:22 +00009#include <stddef.h>
10
11extern "C" {
12
Ivan Krasinf619cdc2011-08-29 22:39:12 +000013// CHECK: @align_c = global i32 1
14int align_c = __alignof(char);
15
16// CHECK: @align_s = global i32 2
17int align_s = __alignof(short);
18
19// CHECK: @align_i = global i32 4
20int align_i = __alignof(int);
21
22// CHECK: @align_l = global i32 4
23int align_l = __alignof(long);
24
25// CHECK: @align_ll = global i32 8
26int align_ll = __alignof(long long);
27
28// CHECK: @align_p = global i32 4
29int align_p = __alignof(void*);
30
31// CHECK: @align_f = global i32 4
32int align_f = __alignof(float);
33
34// CHECK: @align_d = global i32 8
35int align_d = __alignof(double);
36
37// CHECK: @align_ld = global i32 8
38int align_ld = __alignof(long double);
39
40// CHECK: @align_vl = global i32 4
41int align_vl = __alignof(va_list);
42
Jan Wen Voungdde3bdb2012-03-29 00:05:59 +000043// CHECK: __LITTLE_ENDIAN__defined
44#ifdef __LITTLE_ENDIAN__
45void __LITTLE_ENDIAN__defined() {}
46#endif
47
Ivan Krasinf619cdc2011-08-29 22:39:12 +000048// CHECK: __native_client__defined
Ivan Krasinef05abd2011-08-24 20:22:22 +000049#ifdef __native_client__
Ivan Krasinf619cdc2011-08-29 22:39:12 +000050void __native_client__defined() {}
Ivan Krasinef05abd2011-08-24 20:22:22 +000051#endif
52
Ivan Krasinf619cdc2011-08-29 22:39:12 +000053// CHECK: __le32__defined
Ivan Krasinef05abd2011-08-24 20:22:22 +000054#ifdef __le32__
Ivan Krasinf619cdc2011-08-29 22:39:12 +000055void __le32__defined() {}
Ivan Krasinef05abd2011-08-24 20:22:22 +000056#endif
57
Ivan Krasinf619cdc2011-08-29 22:39:12 +000058// CHECK: __pnacl__defined
Ivan Krasinef05abd2011-08-24 20:22:22 +000059#ifdef __pnacl__
Ivan Krasinf619cdc2011-08-29 22:39:12 +000060void __pnacl__defined() {}
Ivan Krasinef05abd2011-08-24 20:22:22 +000061#endif
62
Ivan Krasinf619cdc2011-08-29 22:39:12 +000063// CHECK: unixdefined
Ivan Krasin089ee112011-08-25 23:49:20 +000064#ifdef unix
Ivan Krasinf619cdc2011-08-29 22:39:12 +000065void unixdefined() {}
Ivan Krasin089ee112011-08-25 23:49:20 +000066#endif
67
Ivan Krasinf619cdc2011-08-29 22:39:12 +000068// CHECK: __ELF__defined
Ivan Krasin089ee112011-08-25 23:49:20 +000069#ifdef __ELF__
Ivan Krasinf619cdc2011-08-29 22:39:12 +000070void __ELF__defined() {}
Ivan Krasin089ee112011-08-25 23:49:20 +000071#endif
72
Ivan Krasinf619cdc2011-08-29 22:39:12 +000073// CHECK: _GNU_SOURCEdefined
Ivan Krasin089ee112011-08-25 23:49:20 +000074#ifdef _GNU_SOURCE
Ivan Krasinf619cdc2011-08-29 22:39:12 +000075void _GNU_SOURCEdefined() {}
Ivan Krasin089ee112011-08-25 23:49:20 +000076#endif
77
Ivan Krasinf619cdc2011-08-29 22:39:12 +000078// THREADS: _REENTRANTdefined
79// CHECK: _REENTRANTundefined
80#ifdef _REENTRANT
81void _REENTRANTdefined() {}
82#else
83void _REENTRANTundefined() {}
84#endif
Ivan Krasin089ee112011-08-25 23:49:20 +000085
Ivan Krasinef05abd2011-08-24 20:22:22 +000086// Check types
87
88// CHECK: signext i8 @check_char()
89char check_char() { return 0; }
90
91// CHECK: signext i16 @check_short()
92short check_short() { return 0; }
93
94// CHECK: i32 @check_int()
95int check_int() { return 0; }
96
97// CHECK: i32 @check_long()
98long check_long() { return 0; }
99
100// CHECK: i64 @check_longlong()
101long long check_longlong() { return 0; }
102
103// CHECK: zeroext i8 @check_uchar()
104unsigned char check_uchar() { return 0; }
105
106// CHECK: zeroext i16 @check_ushort()
107unsigned short check_ushort() { return 0; }
108
109// CHECK: i32 @check_uint()
110unsigned int check_uint() { return 0; }
111
112// CHECK: i32 @check_ulong()
113unsigned long check_ulong() { return 0; }
114
115// CHECK: i64 @check_ulonglong()
116unsigned long long check_ulonglong() { return 0; }
117
118// CHECK: i32 @check_size_t()
119size_t check_size_t() { return 0; }
120
121// CHECK: float @check_float()
122float check_float() { return 0; }
123
124// CHECK: double @check_double()
125double check_double() { return 0; }
126
Ivan Krasinbba43ef2011-08-24 21:22:25 +0000127// CHECK: double @check_longdouble()
128long double check_longdouble() { return 0; }
129
Ivan Krasinef05abd2011-08-24 20:22:22 +0000130}
131
Ivan Krasinef05abd2011-08-24 20:22:22 +0000132template<int> void Switch();
133template<> void Switch<4>();
134template<> void Switch<8>();
Ivan Krasinbba43ef2011-08-24 21:22:25 +0000135template<> void Switch<16>();
Ivan Krasinef05abd2011-08-24 20:22:22 +0000136
137void check_pointer_size() {
138 // CHECK: SwitchILi4
139 Switch<sizeof(void*)>();
140
141 // CHECK: SwitchILi8
142 Switch<sizeof(long long)>();
Ivan Krasinbba43ef2011-08-24 21:22:25 +0000143
144 // CHECK: SwitchILi16
145 Switch<sizeof(va_list)>();
Ivan Krasinef05abd2011-08-24 20:22:22 +0000146}