Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 2 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 3 | // Should be 3 hello strings, two global (of different sizes), the rest are |
| 4 | // shared. |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 5 | |
Ulrich Weigand | b840921 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 6 | // CHECK: @align = global i8 [[ALIGN:[0-9]+]] |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 7 | // CHECK: @.str = private unnamed_addr constant [6 x i8] c"hello\00" |
| 8 | // CHECK: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0) |
Ulrich Weigand | b840921 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 9 | // CHECK: @f2.x = internal global [6 x i8] c"hello\00", align [[ALIGN]] |
| 10 | // CHECK: @f3.x = internal global [8 x i8] c"hello\00\00\00", align [[ALIGN]] |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 11 | // CHECK: @f4.x = internal global %struct.s { i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0) } |
Ulrich Weigand | b840921 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 12 | // CHECK: @x = global [3 x i8] c"ola", align [[ALIGN]] |
| 13 | |
| 14 | #if defined(__s390x__) |
| 15 | unsigned char align = 2; |
| 16 | #else |
| 17 | unsigned char align = 1; |
| 18 | #endif |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 19 | |
| 20 | void bar(const char *); |
| 21 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 22 | // CHECK-LABEL: define void @f0() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 23 | void f0() { |
| 24 | bar("hello"); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 25 | // CHECK: call void @bar({{.*}} @.str |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 28 | // CHECK-LABEL: define void @f1() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 29 | void f1() { |
| 30 | static char *x = "hello"; |
| 31 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 32 | // CHECK: [[T1:%.*]] = load i8** @f1.x |
| 33 | // CHECK: call void @bar(i8* [[T1:%.*]]) |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 36 | // CHECK-LABEL: define void @f2() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 37 | void f2() { |
| 38 | static char x[] = "hello"; |
| 39 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 40 | // CHECK: call void @bar({{.*}} @f2.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 43 | // CHECK-LABEL: define void @f3() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 44 | void f3() { |
| 45 | static char x[8] = "hello"; |
| 46 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 47 | // CHECK: call void @bar({{.*}} @f3.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 50 | void gaz(void *); |
| 51 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 52 | // CHECK-LABEL: define void @f4() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 53 | void f4() { |
| 54 | static struct s { |
| 55 | char *name; |
| 56 | } x = { "hello" }; |
| 57 | gaz(&x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 58 | // CHECK: call void @gaz({{.*}} @f4.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Nuno Lopes | 3998d3f | 2008-08-13 23:28:57 +0000 | [diff] [blame] | 61 | char x[3] = "ola"; |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 62 | |