Clang Project

clang_source_code/test/CodeGenCXX/ubsan-nullability-assign.cpp
1// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=nullability-assign | FileCheck %s
2
3struct S1 {
4  int *_Nonnull p;
5};
6
7struct S2 {
8  S1 s1;
9};
10
11union U1 {
12  S1 s1;
13  S2 s2;
14};
15
16// CHECK-LABEL: define void @{{.*}}f1
17void f1(int *p) {
18  U1 u;
19
20  // CHECK: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
21  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
22  // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize
23  // CHECK: store
24  u.s1.p = p;
25
26  // CHECK: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
27  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
28  // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize
29  // CHECK: store
30  u.s2.s1.p = p;
31
32  // CHECK-NOT: __ubsan_handle_type_mismatch
33  // CHECK-NOT: store
34  // CHECK: ret void
35}
36