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>
This commit is contained in:
committed by
Denys Vlasenko
parent
04ad683bf9
commit
5156b24553
16
libbb/const_hack.c
Normal file
16
libbb/const_hack.c
Normal file
@ -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
|
Reference in New Issue
Block a user