xref: /llvm-project/clang/test/CodeGen/noundef-analysis.cpp (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1 // RUN: %clang_cc1 -triple arm64-darwin -enable-noundef-analysis -emit-llvm -o - %s | FileCheck %s -check-prefix ENABLED
2 // RUN: %clang_cc1 -triple arm64-darwin -no-enable-noundef-analysis -emit-llvm -o - %s | FileCheck %s -check-prefix DISABLED
3 
4 union u1 {
5   int val;
6 };
7 
8 struct s1 {
9   int val;
10 };
11 
indirect_callee_int(int a)12 int indirect_callee_int(int a) { return a; }
indirect_callee_union(union u1 a)13 union u1 indirect_callee_union(union u1 a) {
14   return a;
15 }
16 
17 static int sink;
18 
examineValue(int x)19 static void examineValue(int x) { sink = x; }
20 
21 // ENABLED-LABEL: @main(
22 // ENABLED:    [[CALL:%.*]] = call noundef {{.*}}i32 @_Z19indirect_callee_inti(i32 noundef {{.*}}0)
23 // ENABLED:    [[CALL1:%.*]] = call i32 @_Z21indirect_callee_union2u1(i64 {{.*}})
24 // ENABLED:    [[CALL2:%.*]] = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #[[ATTR4:[0-9]+]]
25 // ENABLED:    call void @_ZL12examineValuei(i32 noundef {{.*}})
26 // DISABLED-LABEL: @main(
27 // DISABLED:    [[CALL:%.*]] = call {{.*}}i32 @_Z19indirect_callee_inti(i32 {{.*}}0)
28 // DISABLED:    [[CALL1:%.*]] = call i32 @_Z21indirect_callee_union2u1(i64 {{.*}})
29 // DISABLED:    [[CALL2:%.*]] = call noalias nonnull ptr @_Znwm(i64 4) #[[ATTR4:[0-9]+]]
30 // DISABLED:    call void @_ZL12examineValuei(i32 {{.*}})
main()31 int main() {
32   indirect_callee_int(0);
33   indirect_callee_union((union u1){0});
34 
35   auto s = new s1;
36   examineValue(s->val);
37 
38   return 0;
39 }
40