1 //===-- Holder Class for manipulating va_lists ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_ARG_LIST_H
10 #define LLVM_LIBC_SRC_SUPPORT_ARG_LIST_H
12 #include "src/__support/common.h"
17 namespace __llvm_libc
{
24 LIBC_INLINE
ArgList(va_list vlist
) { va_copy(this->vlist
, vlist
); }
25 LIBC_INLINE
ArgList(ArgList
&other
) { va_copy(this->vlist
, other
.vlist
); }
26 LIBC_INLINE
~ArgList() { va_end(this->vlist
); }
28 LIBC_INLINE ArgList
&operator=(ArgList
&rhs
) {
29 va_copy(vlist
, rhs
.vlist
);
33 template <class T
> LIBC_INLINE T
next_var() { return va_arg(vlist
, T
); }
36 // Used for testing things that use an ArgList when it's impossible to know what
37 // the arguments should be ahead of time. An example of this would be fuzzing,
38 // since a function passed a random input could request unpredictable arguments.
40 size_t arg_counter
= 0;
43 LIBC_INLINE
MockArgList() = default;
44 LIBC_INLINE
MockArgList(va_list) { ; }
45 LIBC_INLINE
MockArgList(MockArgList
&other
) {
46 arg_counter
= other
.arg_counter
;
48 LIBC_INLINE
~MockArgList() = default;
50 LIBC_INLINE MockArgList
&operator=(MockArgList
&rhs
) {
51 arg_counter
= rhs
.arg_counter
;
55 template <class T
> LIBC_INLINE T
next_var() {
57 return T(arg_counter
);
60 size_t read_count() const { return arg_counter
; }
63 } // namespace internal
64 } // namespace __llvm_libc
66 #endif // LLVM_LIBC_SRC_SUPPORT_ARG_LIST_H