xref: /llvm-project/llvm/test/Transforms/FunctionAttrs/out-of-bounds-iterator-bug.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; RUN: opt -passes=function-attrs -S < %s | FileCheck %s
2
3; This checks for a previously existing iterator wraparound bug in
4; FunctionAttrs, and in the process covers corner cases with varargs.
5
6declare void @llvm.va_start(ptr)
7declare void @llvm.va_end(ptr)
8
9define void @va_func(ptr readonly %b, ...) readonly nounwind {
10; CHECK-LABEL: define void @va_func(ptr readonly captures(none) %b, ...)
11 entry:
12  %valist = alloca i8
13  call void @llvm.va_start(ptr %valist)
14  call void @llvm.va_end(ptr %valist)
15  %x = call i32 @caller(ptr %b)
16  ret void
17}
18
19define i32 @caller(ptr %x) {
20; CHECK-LABEL: define noundef i32 @caller(ptr readonly captures(none) %x)
21 entry:
22  call void(ptr,...) @va_func(ptr null, i32 0, i32 0, i32 0, ptr %x)
23  ret i32 42
24}
25
26define void @va_func2(ptr readonly %b, ...) {
27; CHECK-LABEL: define void @va_func2(ptr readonly captures(none) %b, ...)
28 entry:
29  %valist = alloca i8
30  call void @llvm.va_start(ptr %valist)
31  call void @llvm.va_end(ptr %valist)
32  %x = call i32 @caller(ptr %b)
33  ret void
34}
35
36define i32 @caller2(ptr %x, ptr %y) {
37; CHECK-LABEL: define noundef i32 @caller2(ptr readonly captures(none) %x, ptr %y)
38 entry:
39  call void(ptr,...) @va_func2(ptr %x, i32 0, i32 0, i32 0, ptr %y)
40  ret i32 42
41}
42
43