blob: 8bc97f1887e90e41c9d17979e4bba2f41ca193f5 [file] [log] [blame]
Richard Smith0093e122013-03-09 23:56:02 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-C %s
2// RUN: %clang_cc1 -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-C %s
3// RUN: %clang_cc1 -x c++ -std=c++11 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-CXX11 %s
4// RUN: %clang_cc1 -x c -std=c11 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-C11 %s
Douglas Gregor53afad52011-07-29 01:08:54 +00005
6#include <stddef.h>
Seo Sanghyeonad6ebd62007-12-23 03:11:58 +00007
Richard Smith0093e122013-03-09 23:56:02 +00008#ifndef __cplusplus
9typedef __WCHAR_TYPE__ wchar_t;
10typedef __CHAR16_TYPE__ char16_t;
11typedef __CHAR32_TYPE__ char32_t;
12#endif
13
Seo Sanghyeonad6ebd62007-12-23 03:11:58 +000014int main() {
Eric Christopher736a9c22011-08-24 00:33:55 +000015 // CHECK-C: private unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1
Richard Smith0093e122013-03-09 23:56:02 +000016 // CHECK-C11: private unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1
17 // CHECK-CXX11: private unnamed_addr constant [10 x i8] c"abc\00\00\00\00\00\00\00", align 1
Seo Sanghyeonad6ebd62007-12-23 03:11:58 +000018 char a[10] = "abc";
Chris Lattnerdbb1ecc2009-02-26 23:01:51 +000019
Nico Webera0f15b02010-10-06 04:57:26 +000020 // This should convert to utf8.
Eric Christopher736a9c22011-08-24 00:33:55 +000021 // CHECK-C: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1
Richard Smith0093e122013-03-09 23:56:02 +000022 // CHECK-C11: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1
23 // CHECK-CXX11: private unnamed_addr constant [10 x i8] c"\E1\84\A0\C8\A0\F4\82\80\B0\00", align 1
Nico Webera0f15b02010-10-06 04:57:26 +000024 char b[10] = "\u1120\u0220\U00102030";
25
Eli Friedman64f45a22011-11-01 02:23:42 +000026 // CHECK-C: private unnamed_addr constant [3 x i32] [i32 65, i32 66, i32 0], align 4
Richard Smith0093e122013-03-09 23:56:02 +000027 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 65, i32 66, i32 0], align 4
28 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 65, i32 66, i32 0], align 4
Douglas Gregor5cee1192011-07-27 05:40:30 +000029 const wchar_t *foo = L"AB";
Nico Webera0f15b02010-10-06 04:57:26 +000030
Eli Friedman64f45a22011-11-01 02:23:42 +000031 // CHECK-C: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110027, i32 0], align 4
Richard Smith0093e122013-03-09 23:56:02 +000032 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110027, i32 0], align 4
33 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110027, i32 0], align 4
Douglas Gregor5cee1192011-07-27 05:40:30 +000034 const wchar_t *bar = L"\u1234\U0010F00B";
35
Eli Friedman64f45a22011-11-01 02:23:42 +000036 // CHECK-C: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110028, i32 0], align 4
Richard Smith0093e122013-03-09 23:56:02 +000037 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110028, i32 0], align 4
38 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 4660, i32 1110028, i32 0], align 4
Craig Topper2e4f44f2011-08-11 05:57:09 +000039 const wchar_t *baz = L"\u1234" "\U0010F00C";
40
Richard Smith0093e122013-03-09 23:56:02 +000041#if __cplusplus >= 201103L || __STDC_VERSION__ >= 201112L
42 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 67, i32 68, i32 0], align 4
43 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 67, i32 68, i32 0], align 4
Douglas Gregor5cee1192011-07-27 05:40:30 +000044 const char32_t *c = U"CD";
45
Richard Smith0093e122013-03-09 23:56:02 +000046 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 4661, i32 1110028, i32 0], align 4
47 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 4661, i32 1110028, i32 0], align 4
Douglas Gregor5cee1192011-07-27 05:40:30 +000048 const char32_t *d = U"\u1235\U0010F00C";
49
Richard Smith0093e122013-03-09 23:56:02 +000050 // CHECK-C11: private unnamed_addr constant [3 x i32] [i32 4661, i32 1110027, i32 0], align 4
51 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 4661, i32 1110027, i32 0], align 4
Craig Topper2e4f44f2011-08-11 05:57:09 +000052 const char32_t *o = "\u1235" U"\U0010F00B";
53
Richard Smith0093e122013-03-09 23:56:02 +000054 // CHECK-C11: private unnamed_addr constant [3 x i16] [i16 69, i16 70, i16 0], align 2
55 // CHECK-CXX11: private unnamed_addr constant [3 x i16] [i16 69, i16 70, i16 0], align 2
Douglas Gregor5cee1192011-07-27 05:40:30 +000056 const char16_t *e = u"EF";
57
58 // This should convert to utf16.
Richard Smith0093e122013-03-09 23:56:02 +000059 // CHECK-C11: private unnamed_addr constant [5 x i16] [i16 4384, i16 544, i16 -9272, i16 -9168, i16 0], align 2
60 // CHECK-CXX11: private unnamed_addr constant [5 x i16] [i16 4384, i16 544, i16 -9272, i16 -9168, i16 0], align 2
Douglas Gregor5cee1192011-07-27 05:40:30 +000061 const char16_t *f = u"\u1120\u0220\U00102030";
62
Craig Topper2e4f44f2011-08-11 05:57:09 +000063 // This should convert to utf16.
Richard Smith0093e122013-03-09 23:56:02 +000064 // CHECK-C11: private unnamed_addr constant [5 x i16] [i16 4384, i16 800, i16 -9272, i16 -9168, i16 0], align 2
65 // CHECK-CXX11: private unnamed_addr constant [5 x i16] [i16 4384, i16 800, i16 -9272, i16 -9168, i16 0], align 2
Craig Topper2e4f44f2011-08-11 05:57:09 +000066 const char16_t *p = u"\u1120\u0320" "\U00102030";
67
Richard Smith0093e122013-03-09 23:56:02 +000068 // CHECK-C11: private unnamed_addr constant [4 x i8] c"def\00", align 1
69 // CHECK-CXX11: private unnamed_addr constant [4 x i8] c"def\00", align 1
Douglas Gregor5cee1192011-07-27 05:40:30 +000070 const char *g = u8"def";
Craig Topper2fa4e862011-08-11 04:06:15 +000071
Richard Smith0093e122013-03-09 23:56:02 +000072#ifdef __cplusplus
73 // CHECK-CXX11: private unnamed_addr constant [4 x i8] c"ghi\00", align 1
Craig Topper2fa4e862011-08-11 04:06:15 +000074 const char *h = R"foo(ghi)foo";
75
Richard Smith0093e122013-03-09 23:56:02 +000076 // CHECK-CXX11: private unnamed_addr constant [4 x i8] c"jkl\00", align 1
Craig Topper2fa4e862011-08-11 04:06:15 +000077 const char *i = u8R"bar(jkl)bar";
78
Richard Smith0093e122013-03-09 23:56:02 +000079 // CHECK-CXX11: private unnamed_addr constant [3 x i16] [i16 71, i16 72, i16 0], align 2
Craig Topper2fa4e862011-08-11 04:06:15 +000080 const char16_t *j = uR"foo(GH)foo";
81
Richard Smith0093e122013-03-09 23:56:02 +000082 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 73, i32 74, i32 0], align 4
Craig Topper2fa4e862011-08-11 04:06:15 +000083 const char32_t *k = UR"bar(IJ)bar";
84
Richard Smith0093e122013-03-09 23:56:02 +000085 // CHECK-CXX11: private unnamed_addr constant [3 x i32] [i32 75, i32 76, i32 0], align 4
Craig Topper2fa4e862011-08-11 04:06:15 +000086 const wchar_t *l = LR"bar(KL)bar";
87
Richard Smith0093e122013-03-09 23:56:02 +000088 // CHECK-CXX11: private unnamed_addr constant [9 x i8] c"abc\5Cndef\00", align 1
Craig Topper2fa4e862011-08-11 04:06:15 +000089 const char *m = R"(abc\ndef)";
90
Richard Smith0093e122013-03-09 23:56:02 +000091 // CHECK-CXX11: private unnamed_addr constant [8 x i8] c"abc\0Adef\00", align 1
Craig Topper2fa4e862011-08-11 04:06:15 +000092 const char *n = R"(abc
93def)";
94
Richard Smith0093e122013-03-09 23:56:02 +000095 // CHECK-CXX11: private unnamed_addr constant [11 x i8] c"abc\0Adefghi\00", align 1
Craig Topper2e4f44f2011-08-11 05:57:09 +000096 const char *q = R"(abc
97def)" "ghi";
98
Richard Smith0093e122013-03-09 23:56:02 +000099 // CHECK-CXX11: private unnamed_addr constant [13 x i8] c"abc\5C\0A??=\0Adef\00", align 1
Richard Smith30cddae2012-11-28 07:29:00 +0000100 const char *r = R\
101"(abc\
102??=
103def)";
104
Richard Smith0093e122013-03-09 23:56:02 +0000105#endif
Douglas Gregor53afad52011-07-29 01:08:54 +0000106#endif
Seo Sanghyeonad6ebd62007-12-23 03:11:58 +0000107}