blob: 1021010a6ddca04d3388b46dc3ab1c6f7cfb6b55 [file] [log] [blame]
Dmitri Gribenko57e2a162013-01-25 00:06:54 +00001// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
Daniel Dunbar61432932008-08-13 23:20:05 +00002
Dmitri Gribenko57e2a162013-01-25 00:06:54 +00003// Should be 3 hello strings, two global (of different sizes), the rest are
4// shared.
Daniel Dunbar61432932008-08-13 23:20:05 +00005
Dmitri Gribenko57e2a162013-01-25 00:06:54 +00006// 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
13void bar(const char *);
14
15// CHECK: define void @f0()
Daniel Dunbar61432932008-08-13 23:20:05 +000016void f0() {
17 bar("hello");
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000018 // CHECK: call void @bar({{.*}} @.str
Daniel Dunbar61432932008-08-13 23:20:05 +000019}
20
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000021// CHECK: define void @f1()
Daniel Dunbar61432932008-08-13 23:20:05 +000022void f1() {
23 static char *x = "hello";
24 bar(x);
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000025 // CHECK: [[T1:%.*]] = load i8** @f1.x
26 // CHECK: call void @bar(i8* [[T1:%.*]])
Daniel Dunbar61432932008-08-13 23:20:05 +000027}
28
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000029// CHECK: define void @f2()
Daniel Dunbar61432932008-08-13 23:20:05 +000030void f2() {
31 static char x[] = "hello";
32 bar(x);
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000033 // CHECK: call void @bar({{.*}} @f2.x
Daniel Dunbar61432932008-08-13 23:20:05 +000034}
35
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000036// CHECK: define void @f3()
Daniel Dunbar61432932008-08-13 23:20:05 +000037void f3() {
38 static char x[8] = "hello";
39 bar(x);
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000040 // CHECK: call void @bar({{.*}} @f3.x
Daniel Dunbar61432932008-08-13 23:20:05 +000041}
42
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000043void gaz(void *);
44
45// CHECK: define void @f4()
Daniel Dunbar61432932008-08-13 23:20:05 +000046void f4() {
47 static struct s {
48 char *name;
49 } x = { "hello" };
50 gaz(&x);
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000051 // CHECK: call void @gaz({{.*}} @f4.x
Daniel Dunbar61432932008-08-13 23:20:05 +000052}
53
Nuno Lopes3998d3f2008-08-13 23:28:57 +000054char x[3] = "ola";
Dmitri Gribenko57e2a162013-01-25 00:06:54 +000055