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 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 6 | // CHECK: @.str = private unnamed_addr constant [6 x i8] c"hello\00" |
| 7 | // CHECK: @f1.x = internal global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0) |
| 8 | // CHECK: @f2.x = internal global [6 x i8] c"hello\00", align 1 |
| 9 | // CHECK: @f3.x = internal global [8 x i8] c"hello\00\00\00", align 1 |
| 10 | // CHECK: @f4.x = internal global %struct.s { i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0) } |
| 11 | // CHECK: @x = global [3 x i8] c"ola", align 1 |
| 12 | |
| 13 | void bar(const char *); |
| 14 | |
| 15 | // CHECK: define void @f0() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 16 | void f0() { |
| 17 | bar("hello"); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 18 | // CHECK: call void @bar({{.*}} @.str |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 21 | // CHECK: define void @f1() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 22 | void f1() { |
| 23 | static char *x = "hello"; |
| 24 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 25 | // CHECK: [[T1:%.*]] = load i8** @f1.x |
| 26 | // CHECK: call void @bar(i8* [[T1:%.*]]) |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 29 | // CHECK: define void @f2() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 30 | void f2() { |
| 31 | static char x[] = "hello"; |
| 32 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 33 | // CHECK: call void @bar({{.*}} @f2.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 36 | // CHECK: define void @f3() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 37 | void f3() { |
| 38 | static char x[8] = "hello"; |
| 39 | bar(x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 40 | // CHECK: call void @bar({{.*}} @f3.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 43 | void gaz(void *); |
| 44 | |
| 45 | // CHECK: define void @f4() |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 46 | void f4() { |
| 47 | static struct s { |
| 48 | char *name; |
| 49 | } x = { "hello" }; |
| 50 | gaz(&x); |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 51 | // CHECK: call void @gaz({{.*}} @f4.x |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Nuno Lopes | 3998d3f | 2008-08-13 23:28:57 +0000 | [diff] [blame] | 54 | char x[3] = "ola"; |
Dmitri Gribenko | 57e2a16 | 2013-01-25 00:06:54 +0000 | [diff] [blame] | 55 | |