File: load-chain-u8-oob.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (74 lines) | stat: -rw-r--r-- 2,667 bytes parent folder | download | duplicates (14)
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
67
68
69
70
71
72
73
74
; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
;
; Check that bpf-preserve-static-offset folds chain of GEP instructions.
; The GEP chain in this example has unexpected shape and thus is
; folded as i8 access.
;
; Source (IR modified by hand):
;    #define __ctx __attribute__((preserve_static_offset))
;    
;    struct foo {
;      char a[2];
;    };
;    
;    struct bar {
;      char a;
;      struct foo b;
;    } __ctx;
;    
;    extern void consume(char);
;    
;    void buz(struct bar *p) {
;      consume((&p->b)[1].a[1]);
;    }
;
; Compilation flag:
;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
;       | opt -passes=function(sroa) -S -o -
;
; Modified to remove 'inbounds' from one of the GEP instructions.

%struct.bar = type { i8, %struct.foo }
%struct.foo = type { [2 x i8] }

; Function Attrs: nounwind
define dso_local void @buz(ptr noundef %p) #0 {
entry:
  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
  %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 1
  %arrayidx = getelementptr inbounds %struct.foo, ptr %b, i64 1
;                                                         ^^^^^
;                                  folded as i8 access because of this index
  %a = getelementptr %struct.foo, ptr %arrayidx, i32 0, i32 0
  %arrayidx1 = getelementptr inbounds [2 x i8], ptr %a, i64 0, i64 1
  %1 = load i8, ptr %arrayidx1, align 1, !tbaa !2
  call void @consume(i8 noundef signext %1)
  ret void
}

; CHECK:      %[[v1:.*]] = call i8 (ptr, i1, i8, i8, i8, i1, ...)
; CHECK-SAME:    @llvm.bpf.getelementptr.and.load.i8
; CHECK-SAME:      (ptr readonly elementtype(i8) %{{[^,]+}},
; CHECK-SAME:       i1 false, i8 0, i8 1, i8 0, i1 false, i64 immarg 4)
;                                               ^^^^^^^^  ^^^^^^^^^^^^
;                                 not inbounds ---'         |
;               offset from 'struct bar' start -------------'
; CHECK-NEXT: call void @consume(i8 noundef signext %[[v1]])

declare void @consume(i8 noundef signext) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare ptr @llvm.preserve.static.offset(ptr readnone) #2

attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang"}
!2 = !{!3, !3, i64 0}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}