Debian Codegraph @

clang/test/CIR/CodeGen/static-vars.c

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir %s
3
4 void func1(void) {
5 // Should lower default-initialized static vars.
6 static int i;
7 // CHECK-DAG: cir.global "private" internal dso_local @func1.i = #cir.int<0> : !s32i
8
9 // Should lower constant-initialized static vars.
10 static int j = 1;
11 // CHECK-DAG: cir.global "private" internal dso_local @func1.j = #cir.int<1> : !s32i
12
13 // Should properly shadow static vars in nested scopes.
14 {
15 static int j = 2;
16 // CHECK-DAG: cir.global "private" internal dso_local @func1.j.1 = #cir.int<2> : !s32i
17 }
18 {
19 static int j = 3;
20 // CHECK-DAG: cir.global "private" internal dso_local @func1.j.2 = #cir.int<3> : !s32i
21 }
22
23 // Should lower basic static vars arithmetics.
24 j++;
25 // CHECK-DAG: %[[#V2:]] = cir.get_global @func1.j : !cir.ptr<!s32i>
26 // CHECK-DAG: %[[#V3:]] = cir.load{{.*}} %[[#V2]] : !cir.ptr<!s32i>, !s32i
27 // CHECK-DAG: %[[#V4:]] = cir.unary(inc, %[[#V3]]) nsw : !s32i, !s32i
28 // CHECK-DAG: cir.store{{.*}} %[[#V4]], %[[#V2]] : !s32i, !cir.ptr<!s32i>
29 }
30
31 // Should shadow static vars on different functions.
32 void func2(void) {
33 static char i;
34 // CHECK-DAG: cir.global "private" internal dso_local @func2.i = #cir.int<0> : !s8i
35 static float j;
36 // CHECK-DAG: cir.global "private" internal dso_local @func2.j = #cir.fp<0.000000e+00> : !cir.float
37 }