File: ubsan-bool.m

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (66 lines) | stat: -rw-r--r-- 2,126 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// RUN: %clang_cc1 -no-enable-noundef-analysis -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - -w | FileCheck %s -check-prefixes=SHARED,OBJC
// RUN: %clang_cc1 -no-enable-noundef-analysis -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - -w | FileCheck %s -check-prefixes=SHARED,OBJC
// RUN: %clang_cc1 -no-enable-noundef-analysis -x c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - | FileCheck %s -check-prefixes=SHARED,C

typedef signed char BOOL;

// SHARED-LABEL: f1
BOOL f1(void) {
  // OBJC: call void @__ubsan_handle_load_invalid_value
  // C-NOT: call void @__ubsan_handle_load_invalid_value
  BOOL a = 2;
  return a + 1;
  // SHARED: ret i8
}

struct S1 {
  BOOL b1 : 1;
};

// SHARED-LABEL: f2
BOOL f2(struct S1 *s) {
  // OBJC: [[LOAD:%.*]] = load i8, ptr {{.*}}
  // OBJC: [[SHL:%.*]] = shl i8 [[LOAD]], 7
  // OBJC: [[ASHR:%.*]] = ashr i8 [[SHL]], 7
  // OBJC: icmp ule i8 [[ASHR]], 1, !nosanitize
  // OBJC: call void @__ubsan_handle_load_invalid_value

  // C-NOT: call void @__ubsan_handle_load_invalid_value
  return s->b1;
  // SHARED: ret i8
}

#ifdef __OBJC__
@interface I1 {
@public
  BOOL b1 : 1;
}
@property (nonatomic) BOOL b1;
@end
@implementation I1
@synthesize b1;
@end

// Check the synthesized getter.
// OBJC-LABEL: define internal signext i8 @"\01-[I1 b1]"
// OBJC: [[IVAR:%.*]] = load i64, ptr @"OBJC_IVAR_$_I1.b1"
// OBJC: [[ADDR:%.*]] = getelementptr inbounds i8, ptr {{.*}}, i64 [[IVAR]]
// OBJC: [[LOAD:%.*]] = load i8, ptr {{.*}}
// OBJC: [[SHL:%.*]] = shl i8 [[LOAD]], 7
// OBJC: [[ASHR:%.*]] = ashr i8 [[SHL]], 7
// OBJC: icmp ule i8 [[ASHR]], 1, !nosanitize
// OBJC: call void @__ubsan_handle_load_invalid_value

// Also check direct accesses to the ivar.
// OBJC-LABEL: f3
BOOL f3(I1 *i) {
  // OBJC: [[LOAD:%.*]] = load i8, ptr {{.*}}
  // OBJC: [[SHL:%.*]] = shl i8 [[LOAD]], 7
  // OBJC: [[ASHR:%.*]] = ashr i8 [[SHL]], 7
  // OBJC: icmp ule i8 [[ASHR]], 1, !nosanitize
  // OBJC: call void @__ubsan_handle_load_invalid_value

  return i->b1;
  // OBJC: ret i8
}
#endif /* __OBJC__ */