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