function-attributes

Does asmlinkage mean stack or register?

别说谁变了你拦得住时间么 提交于 2021-02-11 12:32:00
问题 In most languages, C included the stack is used for function calls. That's why you get a "Stack Overflow" error if you are not careful in recursion. (Pun not intended). If that is true then what is so special about the asmlinkage GCC directive. It says, from #kernelnewbies The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in

LLVM how to set Attributes::NoUnwind to Function?

梦想的初衷 提交于 2020-01-15 10:14:12
问题 I think this is very simple question, but I can't resolve it. Very sad. So. When I do llc.exe -march=cpp test.bc I get interesting test.cpp with this piece of code: AttrListPtr func__Z2f1i_PAL; { SmallVector<AttributeWithIndex, 4> Attrs; AttributeWithIndex PAWI; PAWI.Index = 4294967295U; PAWI.Attrs = Attribute::None | Attribute::NoUnwind; Attrs.push_back(PAWI); func__Z2f1i_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end()); } But when I want to write string like PAWI.Attrs = Attribute::None |

LLVM how to set Attributes::NoUnwind to Function?

风流意气都作罢 提交于 2020-01-15 10:14:10
问题 I think this is very simple question, but I can't resolve it. Very sad. So. When I do llc.exe -march=cpp test.bc I get interesting test.cpp with this piece of code: AttrListPtr func__Z2f1i_PAL; { SmallVector<AttributeWithIndex, 4> Attrs; AttributeWithIndex PAWI; PAWI.Index = 4294967295U; PAWI.Attrs = Attribute::None | Attribute::NoUnwind; Attrs.push_back(PAWI); func__Z2f1i_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end()); } But when I want to write string like PAWI.Attrs = Attribute::None |

pure/const function attributes in different compilers

我们两清 提交于 2019-12-17 10:52:56
问题 pure is a function attribute which says that a function does not modify any global memory. const is a function attribute which says that a function does not read/modify any global memory. Given that information, the compiler can do some additional optimisations. Example for GCC: float sigmoid(float x) __attribute__ ((const)); float calculate(float x, unsigned int C) { float sum = 0; for(unsigned int i = 0; i < C; ++i) sum += sigmoid(x); return sum; } float sigmoid(float x) { return 1.0f / (1

decorator to set attributes of function

老子叫甜甜 提交于 2019-11-30 13:28:49
I want different functions to be executable only if the logged in user has the required permission level. To make my life more complexly simply I want to use decorators. Below I attempy to set attribute permission on 'decorated' functions - as shown below. def permission(permission_required): def wrapper(func): def inner(*args, **kwargs): setattr(func, 'permission_required', permission_required) return func(*args, **kwargs) return inner return wrapper @permission('user') def do_x(arg1, arg2): ... @permission('admin') def do_y(arg1, arg2): ... But when I do: fn = do_x if logged_in_user.access

decorator to set attributes of function

爷,独闯天下 提交于 2019-11-29 19:06:37
问题 I want different functions to be executable only if the logged in user has the required permission level. To make my life more complexly simply I want to use decorators. Below I attempy to set attribute permission on 'decorated' functions - as shown below. def permission(permission_required): def wrapper(func): def inner(*args, **kwargs): setattr(func, 'permission_required', permission_required) return func(*args, **kwargs) return inner return wrapper @permission('user') def do_x(arg1, arg2):

How to use GCC's printf format attribute with C++11 variadic templates?

∥☆過路亽.° 提交于 2019-11-29 09:17:59
I have a C++ class that is the frontend for a logging system. Its logging function is implemented using C++11's variadic templates: template <typename... Args> void Frontend::log(const char *fmt, Args&&... args) { backend->true_log(fmt, std::forward<Args>(args)...); } Each logging backend implements its own version of true_log , that, among other things, uses the forwarded parameters to call vsnprintf . E.g.: void Backend::true_log(const char *fmt, ...) { // other stuff.. va_list ap; va_start(ap, fmt); vsnprintf(buffer, buffer_length, fmt, ap); va_end(ap); // other stuff.. } Everything works

How to use GCC's printf format attribute with C++11 variadic templates?

[亡魂溺海] 提交于 2019-11-28 02:42:49
问题 I have a C++ class that is the frontend for a logging system. Its logging function is implemented using C++11's variadic templates: template <typename... Args> void Frontend::log(const char *fmt, Args&&... args) { backend->true_log(fmt, std::forward<Args>(args)...); } Each logging backend implements its own version of true_log , that, among other things, uses the forwarded parameters to call vsnprintf . E.g.: void Backend::true_log(const char *fmt, ...) { // other stuff.. va_list ap; va_start

pure/const function attributes in different compilers

烂漫一生 提交于 2019-11-27 13:28:59
pure is a function attribute which says that a function does not modify any global memory. const is a function attribute which says that a function does not read/modify any global memory. Given that information, the compiler can do some additional optimisations. Example for GCC: float sigmoid(float x) __attribute__ ((const)); float calculate(float x, unsigned int C) { float sum = 0; for(unsigned int i = 0; i < C; ++i) sum += sigmoid(x); return sum; } float sigmoid(float x) { return 1.0f / (1.0f - exp(-x)); } In that example, the compiler could optimise the function calculate to: float