diff options
| author | YU Jincheng <shana@zju.edu.cn> | 2021-10-10 02:19:51 +0800 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-09 22:30:45 +0200 |
| commit | 5156b245536ce0f07165793f07c63fd9fa5dd3b7 (patch) | |
| tree | 3b73b7ea8ed1830d9cc13cbce1da6918926553e2 /libbb/const_hack.c | |
| parent | 04ad683bf99333c2a6c6fd6549faa67978ad9a98 (diff) | |
Make const ptr assign as function call in clang
- This can act as memory barrier in clang to avoid
read before assign of a const ptr
Signed-off-by: LoveSy <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/const_hack.c')
| -rw-r--r-- | libbb/const_hack.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libbb/const_hack.c b/libbb/const_hack.c new file mode 100644 index 000000000..9575e6d67 --- /dev/null +++ b/libbb/const_hack.c @@ -0,0 +1,16 @@ +/* vi: set sw=4 ts=4: */ +/* + * Trick to assign a const ptr with barrier for clang + * + * Copyright (C) 2021 by YU Jincheng <shana@zju.edu.cn> + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ +#include "libbb.h" + +#if defined(__clang_major__) && __clang_major__ >= 9 +void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size) +{ + ASSIGN_CONST_PTR(pptr, xzalloc(size)); +} +#endif |
