xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/c-strings.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=ITANIUM
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple %ms_abi_triple -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=MSABI
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc // Should be 3 hello strings, two global (of different sizes), the rest are
5f4a2713aSLionel Sambuc // shared.
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc // CHECK: @align = global i8 [[ALIGN:[0-9]+]]
8*0a6a1f1dSLionel Sambuc // ITANIUM: @.str = private unnamed_addr constant [6 x i8] c"hello\00"
9*0a6a1f1dSLionel Sambuc // MSABI: @"\01??_C@_05CJBACGMB@hello?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"hello\00", align 1
10*0a6a1f1dSLionel Sambuc // ITANIUM: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)
11*0a6a1f1dSLionel Sambuc // MSABI: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @"\01??_C@_05CJBACGMB@hello?$AA@", i32 0, i32 0)
12f4a2713aSLionel Sambuc // CHECK: @f2.x = internal global [6 x i8] c"hello\00", align [[ALIGN]]
13f4a2713aSLionel Sambuc // CHECK: @f3.x = internal global [8 x i8] c"hello\00\00\00", align [[ALIGN]]
14*0a6a1f1dSLionel Sambuc // ITANIUM: @f4.x = internal global %struct.s { i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0) }
15*0a6a1f1dSLionel Sambuc // MSABI: @f4.x = internal global %struct.s { i8* getelementptr inbounds ([6 x i8]* @"\01??_C@_05CJBACGMB@hello?$AA@", i32 0, i32 0) }
16f4a2713aSLionel Sambuc // CHECK: @x = global [3 x i8] c"ola", align [[ALIGN]]
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc #if defined(__s390x__)
19f4a2713aSLionel Sambuc unsigned char align = 2;
20f4a2713aSLionel Sambuc #else
21f4a2713aSLionel Sambuc unsigned char align = 1;
22f4a2713aSLionel Sambuc #endif
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc void bar(const char *);
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f0()
f0()27f4a2713aSLionel Sambuc void f0() {
28f4a2713aSLionel Sambuc   bar("hello");
29*0a6a1f1dSLionel Sambuc   // ITANIUM: call void @bar({{.*}} @.str
30*0a6a1f1dSLionel Sambuc   // MSABI: call void @bar({{.*}} @"\01??_C@_05CJBACGMB@hello?$AA@"
31f4a2713aSLionel Sambuc }
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f1()
f1()34f4a2713aSLionel Sambuc void f1() {
35f4a2713aSLionel Sambuc   static char *x = "hello";
36f4a2713aSLionel Sambuc   bar(x);
37f4a2713aSLionel Sambuc   // CHECK: [[T1:%.*]] = load i8** @f1.x
38f4a2713aSLionel Sambuc   // CHECK: call void @bar(i8* [[T1:%.*]])
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f2()
f2()42f4a2713aSLionel Sambuc void f2() {
43f4a2713aSLionel Sambuc   static char x[] = "hello";
44f4a2713aSLionel Sambuc   bar(x);
45f4a2713aSLionel Sambuc   // CHECK: call void @bar({{.*}} @f2.x
46f4a2713aSLionel Sambuc }
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f3()
f3()49f4a2713aSLionel Sambuc void f3() {
50f4a2713aSLionel Sambuc   static char x[8] = "hello";
51f4a2713aSLionel Sambuc   bar(x);
52f4a2713aSLionel Sambuc   // CHECK: call void @bar({{.*}} @f3.x
53f4a2713aSLionel Sambuc }
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc void gaz(void *);
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f4()
f4()58f4a2713aSLionel Sambuc void f4() {
59f4a2713aSLionel Sambuc   static struct s {
60f4a2713aSLionel Sambuc     char *name;
61f4a2713aSLionel Sambuc   } x = { "hello" };
62f4a2713aSLionel Sambuc   gaz(&x);
63f4a2713aSLionel Sambuc   // CHECK: call void @gaz({{.*}} @f4.x
64f4a2713aSLionel Sambuc }
65f4a2713aSLionel Sambuc 
66f4a2713aSLionel Sambuc char x[3] = "ola";
67f4a2713aSLionel Sambuc 
68