• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -asan -asan-detect-invalid-pointer-cmp -S -enable-new-pm=0 \
2; RUN:     | FileCheck %s --check-prefixes=CMP,NOSUB,ALL
3; RUN: opt < %s -passes='asan-function-pipeline' -asan-detect-invalid-pointer-cmp -S \
4; RUN:     | FileCheck %s --check-prefixes=CMP,NOSUB,ALL
5; RUN: opt < %s -asan -asan-detect-invalid-pointer-sub -S -enable-new-pm=0 \
6; RUN:     | FileCheck %s --check-prefixes=SUB,NOCMP,ALL
7; RUN: opt < %s -passes='asan-function-pipeline' -asan-detect-invalid-pointer-sub -S \
8; RUN:     | FileCheck %s --check-prefixes=SUB,NOCMP,ALL
9; RUN: opt < %s -asan -asan-detect-invalid-pointer-pair -S -enable-new-pm=0 \
10; RUN:     | FileCheck %s --check-prefixes=CMP,SUB,ALL
11; RUN: opt < %s -passes='asan-function-pipeline' -asan-detect-invalid-pointer-pair -S \
12; RUN:     | FileCheck %s --check-prefixes=CMP,SUB,ALL
13; Support instrumentation of invalid pointer pair detection.
14
15target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
16
17define i32 @mycmp(i8* %p, i8* %q) sanitize_address {
18; ALL-LABEL: @mycmp
19; NOCMP-NOT: call void @__sanitizer_ptr_cmp
20; CMP: [[P:%[0-9A-Za-z]+]] = ptrtoint i8* %p to i64
21; CMP: [[Q:%[0-9A-Za-z]+]] = ptrtoint i8* %q to i64
22  %x = icmp ule i8* %p, %q
23; CMP: call void @__sanitizer_ptr_cmp(i64 [[P]], i64 [[Q]])
24  %y = zext i1 %x to i32
25  ret i32 %y
26}
27
28define i32 @mysub(i8* %p, i8* %q) sanitize_address {
29; ALL-LABEL: @mysub
30; NOSUB-NOT: call void @__sanitizer_ptr_sub
31; SUB: [[P:%[0-9A-Za-z]+]] = ptrtoint i8* %p to i64
32; SUB: [[Q:%[0-9A-Za-z]+]] = ptrtoint i8* %q to i64
33  %x = ptrtoint i8* %p to i64
34  %y = ptrtoint i8* %q to i64
35  %z = sub i64 %x, %y
36; SUB: call void @__sanitizer_ptr_sub(i64 [[P]], i64 [[Q]])
37  %w = trunc i64 %z to i32
38  ret i32 %w
39}
40