Skip to content

Commit 96b3969

Browse files
authored
[NFC][HWASAN] Precommit globals-access test
HWASAN does not behave as expected yet. Reviewers: fmayer, thurstond Reviewed By: fmayer, thurstond Pull Request: #86771
1 parent 35d55f2 commit 96b3969

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --global-value-regex "x" --version 4
2+
; RUN: opt < %s -S -passes=hwasan -mtriple=aarch64 -hwasan-globals=0 | FileCheck %s --check-prefixes=NOGLOB
3+
; RUN: opt < %s -S -passes=hwasan -mtriple=aarch64 -hwasan-globals=1 | FileCheck %s
4+
5+
@x = dso_local global i32 0, align 4
6+
7+
;.
8+
; NOGLOB: @x = dso_local global i32 0, align 4
9+
;.
10+
; CHECK: @x = alias i32, inttoptr (i64 add (i64 ptrtoint (ptr @x.hwasan to i64), i64 5260204364768739328) to ptr)
11+
;.
12+
define dso_local noundef i32 @_Z3tmpv() sanitize_hwaddress {
13+
; NOGLOB-LABEL: define dso_local noundef i32 @_Z3tmpv(
14+
; NOGLOB-SAME: ) #[[ATTR0:[0-9]+]] {
15+
; NOGLOB-NEXT: entry:
16+
; NOGLOB-NEXT: [[TMP12:%.*]] = load i64, ptr @__hwasan_tls, align 8
17+
; NOGLOB-NEXT: [[TMP1:%.*]] = or i64 [[TMP12]], 4294967295
18+
; NOGLOB-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP1]], 1
19+
; NOGLOB-NEXT: [[TMP2:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
20+
; NOGLOB-NEXT: [[TMP3:%.*]] = lshr i64 ptrtoint (ptr @x to i64), 56
21+
; NOGLOB-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i8
22+
; NOGLOB-NEXT: [[TMP5:%.*]] = and i64 ptrtoint (ptr @x to i64), 72057594037927935
23+
; NOGLOB-NEXT: [[TMP6:%.*]] = lshr i64 [[TMP5]], 4
24+
; NOGLOB-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP6]]
25+
; NOGLOB-NEXT: [[TMP8:%.*]] = load i8, ptr [[TMP7]], align 1
26+
; NOGLOB-NEXT: [[TMP9:%.*]] = icmp ne i8 [[TMP4]], [[TMP8]]
27+
; NOGLOB-NEXT: br i1 [[TMP9]], label [[TMP10:%.*]], label [[TMP11:%.*]], !prof [[PROF1:![0-9]+]]
28+
; NOGLOB: 10:
29+
; NOGLOB-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[TMP2]], ptr @x, i32 2)
30+
; NOGLOB-NEXT: br label [[TMP11]]
31+
; NOGLOB: 11:
32+
; NOGLOB-NEXT: [[TMP0:%.*]] = load i32, ptr @x, align 4
33+
; NOGLOB-NEXT: ret i32 [[TMP0]]
34+
;
35+
; CHECK-LABEL: define dso_local noundef i32 @_Z3tmpv(
36+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
37+
; CHECK-NEXT: entry:
38+
; CHECK-NEXT: [[TMP12:%.*]] = load i64, ptr @__hwasan_tls, align 8
39+
; CHECK-NEXT: [[TMP1:%.*]] = or i64 [[TMP12]], 4294967295
40+
; CHECK-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP1]], 1
41+
; CHECK-NEXT: [[TMP2:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
42+
; CHECK-NEXT: [[TMP3:%.*]] = lshr i64 ptrtoint (ptr @x to i64), 56
43+
; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i8
44+
; CHECK-NEXT: [[TMP5:%.*]] = and i64 ptrtoint (ptr @x to i64), 72057594037927935
45+
; CHECK-NEXT: [[TMP6:%.*]] = lshr i64 [[TMP5]], 4
46+
; CHECK-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP6]]
47+
; CHECK-NEXT: [[TMP8:%.*]] = load i8, ptr [[TMP7]], align 1
48+
; CHECK-NEXT: [[TMP9:%.*]] = icmp ne i8 [[TMP4]], [[TMP8]]
49+
; CHECK-NEXT: br i1 [[TMP9]], label [[TMP10:%.*]], label [[TMP11:%.*]], !prof [[PROF2:![0-9]+]]
50+
; CHECK: 10:
51+
; CHECK-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[TMP2]], ptr @x, i32 2)
52+
; CHECK-NEXT: br label [[TMP11]]
53+
; CHECK: 11:
54+
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @x, align 4
55+
; CHECK-NEXT: ret i32 [[TMP0]]
56+
;
57+
entry:
58+
%0 = load i32, ptr @x, align 4
59+
ret i32 %0
60+
}

0 commit comments

Comments
 (0)