xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/char-literal.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-C %s
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-C %s
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -x c++ -std=c++11 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-CPP0X %s
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc #include <stddef.h>
6*f4a2713aSLionel Sambuc 
main()7*f4a2713aSLionel Sambuc int main() {
8*f4a2713aSLionel Sambuc   // CHECK-C: store i8 97
9*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i8 97
10*f4a2713aSLionel Sambuc   char a = 'a';
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc   // Should truncate value (equal to last character).
13*f4a2713aSLionel Sambuc   // CHECK-C: store i8 98
14*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i8 98
15*f4a2713aSLionel Sambuc   char b = 'ab';
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc   // Should get concatenated characters
18*f4a2713aSLionel Sambuc   // CHECK-C: store i32 24930
19*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 24930
20*f4a2713aSLionel Sambuc   int b1 = 'ab';
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   // Should get concatenated characters
23*f4a2713aSLionel Sambuc   // CHECK-C: store i32 808464432
24*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 808464432
25*f4a2713aSLionel Sambuc   int b2 = '0000';
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc   // Should get truncated value (last four characters concatenated)
28*f4a2713aSLionel Sambuc   // CHECK-C: store i32 1919512167
29*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 1919512167
30*f4a2713aSLionel Sambuc   int b3 = 'somesillylongstring';
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc   // CHECK-C: store i32 97
33*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 97
34*f4a2713aSLionel Sambuc   wchar_t wa = L'a';
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc   // Should pick second character.
37*f4a2713aSLionel Sambuc   // CHECK-C: store i32 98
38*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 98
39*f4a2713aSLionel Sambuc   wchar_t wb = L'ab';
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc #if __cplusplus >= 201103L
42*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i16 97
43*f4a2713aSLionel Sambuc   char16_t ua = u'a';
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 97
46*f4a2713aSLionel Sambuc   char32_t Ua = U'a';
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i16 1047
49*f4a2713aSLionel Sambuc   char16_t ua1 = u'З';
50*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i16 12538
51*f4a2713aSLionel Sambuc   char16_t ua2 = u'ヺ';
52*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i16 -27177
53*f4a2713aSLionel Sambuc   char16_t ua3 = u'闗';
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 181
56*f4a2713aSLionel Sambuc   char32_t Ua1 = U'µ';
57*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 38359
58*f4a2713aSLionel Sambuc   char32_t Ua2 = U'闗';
59*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 128128
60*f4a2713aSLionel Sambuc   char32_t Ua3 = U'��';
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc #endif
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc   // CHECK-C: store i32 61451
65*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 61451
66*f4a2713aSLionel Sambuc   wchar_t wc = L'\uF00B';
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc #if __cplusplus >= 201103L
69*f4a2713aSLionel Sambuc   // -4085 == 0xf00b
70*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i16 -4085
71*f4a2713aSLionel Sambuc   char16_t uc = u'\uF00B';
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 61451
74*f4a2713aSLionel Sambuc   char32_t Uc = U'\uF00B';
75*f4a2713aSLionel Sambuc #endif
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc   // CHECK-C: store i32 1110027
78*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 1110027
79*f4a2713aSLionel Sambuc   wchar_t wd = L'\U0010F00B';
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc #if __cplusplus >= 201103L
82*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 1110027
83*f4a2713aSLionel Sambuc   char32_t Ud = U'\U0010F00B';
84*f4a2713aSLionel Sambuc #endif
85*f4a2713aSLionel Sambuc 
86*f4a2713aSLionel Sambuc   // Should pick second character.
87*f4a2713aSLionel Sambuc   // CHECK-C: store i32 1110027
88*f4a2713aSLionel Sambuc   // CHECK-CPP0X: store i32 1110027
89*f4a2713aSLionel Sambuc   wchar_t we = L'\u1234\U0010F00B';
90*f4a2713aSLionel Sambuc }
91