xref: /llvm-project/llvm/test/Analysis/Lint/noalias-byval.ll (revision c0682840877a21960f4c21a97b5f497d4ccc82d5)
1; RUN: opt < %s -passes=lint -disable-output 2>&1 | FileCheck %s
2
3%s = type { i8 }
4
5; Function Attrs: argmemonly nounwind
6declare void @llvm.memcpy.p0.p0.i32(ptr nocapture writeonly, ptr nocapture readonly, i32, i1) #0
7
8; Function Attrs: argmemonly nounwind
9declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1) #0
10
11declare void @f1(ptr noalias nocapture sret(%s), ptr nocapture)
12
13define void @f2() {
14entry:
15  %c = alloca %s
16  %tmp = alloca %s
17  call void @llvm.memset.p0.i32(ptr %c, i8 0, i32 1, i1 false)
18  call void @f1(ptr sret(%s) %c, ptr %c)
19  ret void
20}
21
22; Lint should complain about us passing %c to both arguments since one of them
23; is noalias.
24; CHECK: Unusual: noalias argument aliases another argument
25; CHECK-NEXT: call void @f1(ptr sret(%s) %c, ptr %c)
26
27declare void @f3(ptr noalias nocapture sret(%s), ptr byval(%s) nocapture readnone)
28
29define void @f4() {
30entry:
31  %c = alloca %s
32  %tmp = alloca %s
33  call void @llvm.memset.p0.i32(ptr %c, i8 0, i32 1, i1 false)
34  call void @f3(ptr sret(%s) %c, ptr byval(%s) %c)
35  ret void
36}
37
38; Lint should not complain about passing %c to both arguments even if one is
39; noalias, since the other one is byval, effectively copying the data to the
40; stack instead of passing the pointer itself.
41; CHECK-NOT: Unusual: noalias argument aliases another argument
42; CHECK-NOT: call void @f3(ptr sret(%s) %c, ptr byval(%s) %c)
43
44attributes #0 = { argmemonly nounwind }
45