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