Debian Codegraph @

clang/test/CIR/CodeGen/no-prototype.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 //===----------------------------------------------------------------------===//
5 // DEFINED BEHAVIOUR
6 //===----------------------------------------------------------------------===//
7
8 // No-proto definition followed by a correct call.
9 int noProto0(x) int x; { return x; }
10 // CHECK: cir.func {{.*}} no_proto {{.*}} @noProto0(%arg0: !s32i {{.+}}) -> !s32i
11 int test0(int x) {
12 // CHECK: cir.func {{.*}} @test0
13 return noProto0(x); // We know the definition. Should be a direct call.
14 // CHECK: %{{.+}} = cir.call @noProto0(%{{.+}})
15 }
16
17 // Declaration without prototype followed by its definition, then a correct call.
18 //
19 // Prototyped definition overrides no-proto declaration before any call is made,
20 // only allowing calls with proper arguments. This is the only case where the
21 // definition is not marked as no-proto.
22 int noProto1();
23 int noProto1(int x) { return x; }
24 // CHECK: cir.func {{.*}} @noProto1(%arg0: !s32i {{.+}}) -> !s32i
25 int test1(int x) {
26 // CHECK: cir.func {{.*}} @test1
27 return noProto1(x);
28 // CHECK: %{{.+}} = cir.call @noProto1(%{{[0-9]+}}) : (!s32i) -> !s32i
29 }
30
31 // Declaration without prototype followed by a correct call, then its definition.
32 //
33 // Call to no-proto is made before definition, so a variadic call that takes anything
34 // is created. Later, when the definition is found, no-proto is replaced.
35 int noProto2();
36 int test2(int x) {
37 return noProto2(x);
38 // CHECK: [[GGO:%.*]] = cir.get_global @noProto2 : !cir.ptr<!cir.func<(!s32i) -> !s32i>>
39 // CHECK: {{.*}} = cir.call [[GGO]](%{{[0-9]+}}) : (!cir.ptr<!cir.func<(!s32i) -> !s32i>>, !s32i) -> !s32i
40 }
41 int noProto2(int x) { return x; }
42 // CHECK: cir.func {{.*}} no_proto {{.*}} @noProto2(%arg0: !s32i {{.+}}) -> !s32i
43
44 // No-proto declaration without definition (any call here is "correct").
45 //
46 // Call to no-proto is made before definition, so a variadic call that takes anything
47 // is created. Definition is not in the translation unit, so it is left as is.
48 int noProto3();
49 // cir.func private no_proto @noProto3(...) -> !s32i
50 int test3(int x) {
51 // CHECK: cir.func {{.*}} @test3
52 return noProto3(x);
53 // CHECK: [[GGO:%.*]] = cir.get_global @noProto3 : !cir.ptr<!cir.func<(...) -> !s32i>>
54 // CHECK: [[CAST:%.*]] = cir.cast bitcast [[GGO]] : !cir.ptr<!cir.func<(...) -> !s32i>> -> !cir.ptr<!cir.func<(!s32i) -> !s32i>>
55 // CHECK: {{%.*}} = cir.call [[CAST]](%{{[0-9]+}}) : (!cir.ptr<!cir.func<(!s32i) -> !s32i>>, !s32i) -> !s32i
56 }
57
58
59 //===----------------------------------------------------------------------===//
60 // UNDEFINED BEHAVIOUR
61 //
62 // No-proto definitions followed by incorrect calls.
63 //===----------------------------------------------------------------------===//
64
65 // No-proto definition followed by an incorrect call due to extra args.
66 int noProto4() { return 0; }
67 // cir.func {{.*}} no_proto {{.*}} @noProto4() -> !s32i
68 int test4(int x) {
69 return noProto4(x); // Even if we know the definition, this should compile.
70 // CHECK: [[GGO:%.*]] = cir.get_global @noProto4 : !cir.ptr<!cir.func<() -> !s32i>>
71 // CHECK: [[CAST:%.*]] = cir.cast bitcast [[GGO]] : !cir.ptr<!cir.func<() -> !s32i>> -> !cir.ptr<!cir.func<(!s32i) -> !s32i>>
72 // CHECK: {{%.*}} = cir.call [[CAST]]({{%.*}}) : (!cir.ptr<!cir.func<(!s32i) -> !s32i>>, !s32i) -> !s32i
73 }
74
75 // No-proto definition followed by an incorrect call due to lack of args.
76 int noProto5();
77 int test5(int x) {
78 return noProto5();
79 // CHECK: [[GGO:%.*]] = cir.get_global @noProto5 : !cir.ptr<!cir.func<(!s32i) -> !s32i>>
80 // CHECK: [[CAST:%.*]] = cir.cast bitcast [[GGO]] : !cir.ptr<!cir.func<(!s32i) -> !s32i>> -> !cir.ptr<!cir.func<() -> !s32i>>
81 // CHECK: {{%.*}} = cir.call [[CAST]]() : (!cir.ptr<!cir.func<() -> !s32i>>) -> !s32i
82 }
83 int noProto5(int x) { return x; }
84 // CHECK: cir.func {{.*}} no_proto {{.*}} @noProto5(%arg0: !s32i {{.+}}) -> !s32i