69 lines · plain
1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check that bpf-preserve-static-offset folds chain of GEP instructions.4; The GEP chain in this example has type mismatch and thus is5; folded as i8 access.6;7; Source:8; #define __ctx __attribute__((preserve_static_offset))9; 10; struct foo {11; char aa;12; char bb;13; };14; 15; struct bar {16; char a;17; struct foo b;18; } __ctx;19; 20; void buz(struct bar *p) {21; ((struct foo *)(((char*)&p->b) + 1))->bb = 42;22; }23;24; Compilation flag:25; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \26; | opt -passes=function(sroa) -S -o -27 28%struct.bar = type { i8, %struct.foo }29%struct.foo = type { i8, i8 }30 31; Function Attrs: nounwind32define dso_local void @buz(ptr noundef %p) #0 {33entry:34 %0 = call ptr @llvm.preserve.static.offset(ptr %p)35 %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 136 %add.ptr = getelementptr inbounds i8, ptr %b, i64 137; ~~38; these types do not match, thus GEP chain is folded as an offset39; ~~~~~~~~~~~40 %bb = getelementptr inbounds %struct.foo, ptr %add.ptr, i32 0, i32 141 store i8 42, ptr %bb, align 1, !tbaa !242 ret void43}44 45; CHECK: define dso_local void @buz(ptr noundef writeonly captures(none) %[[p:.*]])46; CHECK: tail call void (i8, ptr, i1, i8, i8, i8, i1, ...)47; CHECK-SAME: @llvm.bpf.getelementptr.and.store.i848; CHECK-SAME: (i8 42,49; CHECK-SAME: ptr writeonly elementtype(i8) %[[p]],50; CHECK-SAME: i1 false, i8 0, i8 1, i8 0, i1 true, i64 immarg 3)51; CHECK-SAME: #[[v2:.*]], !tbaa ![[v3:.*]]52; CHECK: attributes #[[v2]] = { memory(argmem: write) }53 54; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)55declare ptr @llvm.preserve.static.offset(ptr readnone) #156 57attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }58attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }59 60!llvm.module.flags = !{!0}61!llvm.ident = !{!1}62 63!0 = !{i32 1, !"wchar_size", i32 4}64!1 = !{!"clang"}65!2 = !{!3, !4, i64 1}66!3 = !{!"foo", !4, i64 0, !4, i64 1}67!4 = !{!"omnipotent char", !5, i64 0}68!5 = !{!"Simple C/C++ TBAA"}69