Debian Codegraph @

clang/test/CodeGen/decl.c

raw
1 // RUN: %clang_cc1 -std=c89 -w -fmerge-all-constants -emit-llvm < %s | FileCheck %s
2
3 // CHECK: @test1.x = internal constant [12 x i32] [i32 1
4 // CHECK: @__const.test2.x = private unnamed_addr constant [13 x i32] [i32 1,
5 // CHECK: @test5w = {{(dso_local )?}}global { i32, [4 x i8] } { i32 2, [4 x i8] zeroinitializer }
6 // CHECK: @test5y = {{(dso_local )?}}global { double } { double 7.300000e+0{{[0]*}}1 }
7
8 // CHECK: @__const.test6.x = private unnamed_addr constant { i8, i8, [2 x i8], i32, i32 } { i8 1, i8 2, [2 x i8] zeroinitializer, i32 3, i32 0 }
9
10 // CHECK: @test7 = {{(dso_local )?}}global [2 x %struct.test7s] [%struct.test7s { i32 1, i32 2 }, %struct.test7s { i32 4, i32 0 }]
11
12 void test1(void) {
13 // This should codegen as a "@test1.x" global.
14 const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
15 foo(x);
16
17 // CHECK: @test1()
18 // CHECK: {{call.*@foo.*@test1.x}}
19 }
20
21
22 void test2(void) {
23 // This should codegen as a "@test2.x" global + memcpy.
24 int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23, 24 };
25 foo(x);
26
27 // CHECK: @test2()
28 // CHECK: %x = alloca [13 x i32]
29 // CHECK: call void @llvm.memcpy
30 // CHECK: call{{.*}}@foo{{.*}}ptr noundef %
31 }
32
33
34 void test3(void) {
35 // This should codegen as a memset.
36 int x[100] = { 0 };
37 foo(x);
38
39 // CHECK: @test3()
40 // CHECK: %x = alloca [100 x i32]
41 // CHECK: call void @llvm.memset
42 }
43
44 void test4(void) {
45 char a[10] = "asdf";
46 char b[10] = { "asdf" };
47 // CHECK: @test4()
48 // CHECK: %a = alloca [10 x i8]
49 // CHECK: %b = alloca [10 x i8]
50 // CHECK: call void @llvm.memcpy
51 // CHECK: call void @llvm.memcpy
52 }
53
54
55 union test5u { int i; double d; };
56
57 void test5(void) {
58 union test5u ola = (union test5u) 351;
59 union test5u olb = (union test5u) 1.0;
60 }
61
62 union test5u test5w = (union test5u)2;
63 union test5u test5y = (union test5u)73.0;
64
65
66
67 // PR6660 - sqlite miscompile
68 struct SelectDest {
69 unsigned char eDest;
70 unsigned char affinity;
71 int iParm;
72 int iMem;
73 };
74
75 void test6(void) {
76 struct SelectDest x = {1, 2, 3};
77 test6f(&x);
78 }
79
80 struct test7s { int a; int b; } test7[] = {
81 {1, 2},
82 {4},
83 };
84
85 #pragma pack(push, 2)
86 struct test8s { int f0; char f1; } test8g = {};
87
88
89 // PR7519
90
91 struct S {
92 void (*x) (struct S *);
93 };
94
95 extern struct S *global_dc;
96 void cp_diagnostic_starter(struct S *);
97
98 void init_error(void) {
99 global_dc->x = cp_diagnostic_starter;
100 }
101
102
103
104 // ABI crash in recursive struct-through-function-pointer.
105 typedef struct {
106 int x5a;
107 } x5;
108
109 typedef struct x2 *x0;
110 typedef long (*x1)(x0 x0a, x5 x6);
111 struct x2 {
112 x1 x4;
113 };
114 long x3(x0 x0a, x5 a) {
115 return x0a->x4(x0a, a);
116 }