From 920df52a93099860be81e7087773e96e99a49616 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Thu, 15 Feb 2018 17:06:45 +0000 Subject: bpf: fix a bug in dag2dag optimization for loads from readonly section The reference '&' is missing in the function parameter. If there are back-to-back optimizations in terms of dag node list like below: t29: i64,ch = load t3, t43, undef:i64 t34: i64,ch = load t3, t41, undef:i64 The bug will trigger a segfault for the added test case remove_truncate_5.ll: LLVMSymbolizer: error reading file: No such file or directory #0 0x000000000241c4d9 (llc+0x241c4d9) #1 0x000000000241c56a (llc+0x241c56a) #2 0x000000000241aa50 (llc+0x241aa50) ... #22 0x0000000000fd5edf (llc+0xfd5edf) #23 0x00007f0fe03bec05 __libc_start_main (/lib64/libc.so.6+0x21c05) #24 0x0000000000fd3e69 (llc+0xfd3e69) ... Segmentation fault Signed-off-by: Yonghong Song llvm-svn: 325267 --- llvm/test/CodeGen/BPF/remove_truncate_5.ll | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 llvm/test/CodeGen/BPF/remove_truncate_5.ll (limited to 'llvm/test') diff --git a/llvm/test/CodeGen/BPF/remove_truncate_5.ll b/llvm/test/CodeGen/BPF/remove_truncate_5.ll new file mode 100644 index 00000000000..294f93dab9d --- /dev/null +++ b/llvm/test/CodeGen/BPF/remove_truncate_5.ll @@ -0,0 +1,53 @@ +; RUN: llc < %s -march=bpfel | FileCheck -check-prefixes=CHECK %s + +; Source code: +; struct test_t { +; int a; +; char b; +; int c; +; char d; +; }; +; void foo(void *); +; void test() { +; struct test_t t = {.a = 5}; +; foo(&t); +; } + +%struct.test_t = type { i32, i8, i32, i8 } + +@test.t = private unnamed_addr constant %struct.test_t { i32 5, i8 0, i32 0, i8 0 }, align 4 + +; Function Attrs: nounwind +define dso_local void @test() local_unnamed_addr #0 { +; CHECK-LABEL: test: + %1 = alloca %struct.test_t, align 4 + %2 = bitcast %struct.test_t* %1 to i8* + call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %2) #3 + call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 %2, i8* align 4 bitcast (%struct.test_t* @test.t to i8*), i64 16, i1 false) +; CHECK: r1 = 0 +; CHECK: r1 <<= 32 +; CHECK: r2 = r1 +; CHECK: r2 |= 0 +; CHECK: *(u64 *)(r10 - 8) = r2 +; CHECK: r1 |= 5 +; CHECK: *(u64 *)(r10 - 16) = r1 + call void @foo(i8* nonnull %2) #3 +; CHECK: call foo + call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %2) #3 + ret void +} + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 + +; Function Attrs: argmemonly nounwind +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1 + +declare dso_local void @foo(i8*) local_unnamed_addr + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 + +attributes #0 = { nounwind } +attributes #1 = { argmemonly nounwind } +attributes #3 = { nounwind } -- cgit v1.2.3