xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/staticinit.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o %t %s
2*f4a2713aSLionel Sambuc // RUN: grep "g.b = internal global i8. getelementptr" %t
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc struct AStruct {
5*f4a2713aSLionel Sambuc   int i;
6*f4a2713aSLionel Sambuc   char *s;
7*f4a2713aSLionel Sambuc   double d;
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
f()10*f4a2713aSLionel Sambuc void f() {
11*f4a2713aSLionel Sambuc   static int i = 42;
12*f4a2713aSLionel Sambuc   static int is[] = { 1, 2, 3, 4 };
13*f4a2713aSLionel Sambuc   static char* str = "forty-two";
14*f4a2713aSLionel Sambuc   static char* strs[] = { "one", "two", "three", "four" };
15*f4a2713aSLionel Sambuc   static struct AStruct myStruct = { 1, "two", 3.0 };
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
g()18*f4a2713aSLionel Sambuc void g() {
19*f4a2713aSLionel Sambuc   static char a[10];
20*f4a2713aSLionel Sambuc   static char *b = a;
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct s { void *p; };
24*f4a2713aSLionel Sambuc 
foo(void)25*f4a2713aSLionel Sambuc void foo(void) {
26*f4a2713aSLionel Sambuc   static struct s var = {((void*)&((char*)0)[0])};
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc // RUN: grep "f1.l0 = internal global i32 ptrtoint (i32 ()\* @f1 to i32)" %t
f1(void)30*f4a2713aSLionel Sambuc int f1(void) { static int l0 = (unsigned) f1; }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc // PR7044
f2(char key)33*f4a2713aSLionel Sambuc char *f2(char key) {
34*f4a2713aSLionel Sambuc   switch (key) {
35*f4a2713aSLionel Sambuc     static char _msg[40];
36*f4a2713aSLionel Sambuc   case '\014':
37*f4a2713aSLionel Sambuc     return _msg;
38*f4a2713aSLionel Sambuc   }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc   return 0;
41*f4a2713aSLionel Sambuc }
42