Questions tagged [function-attributes]

36 questions
3
votes
1 answer

Explain force_align_arg_pointer function attribute

From the GCC documentation On the Intel x86, the force_align_arg_pointer attribute may be applied to individual function definitions, generating an alternate prologue and epilogue that realigns the runtime stack. This supports mixing legacy codes…
manav m-n
  • 11,136
  • 23
  • 74
  • 97
2
votes
1 answer

Is it possible to declare the function's attribute outside of where it is defined? (GCC)

In GCC, many function attributes can be used to give syntax to the compiler for useful optimization/profiling of the code. Helpful link: https://www.acrc.bris.ac.uk/acrc/RedHat/rhel-gcc-en-4/function-attributes.html For instance, the typical usage…
Jay
  • 373
  • 1
  • 10
2
votes
4 answers

Forcing a function to be optimized on clang or prologueless non-naked C functions - paste together blocks of asm based on C constants

Is there anyway to force a C function on clang to be optimized even when the file is compiled with -O0? I'm looking for something equivalent to gcc's __attribute((optimize("s")) or __attribute((optimize(3)). (Related: In clang, how do you use…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
2
votes
2 answers

Does asmlinkage mean stack or registers?

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…
ng.newbie
  • 2,807
  • 3
  • 23
  • 57
2
votes
2 answers

Why is no warning given for the wrong use of __attribute__((pure)) in GCC?

I am trying to understand pure functions, and have been reading through the Wikipedia article on that topic. I wrote the minimal sample program as follows: #include static int a = 1; static __attribute__((pure)) int pure_function(int x,…
2
votes
2 answers

Optimization problem with [[gnu::pure]] function attribute and threads

I have a program which nearly immediately finishes with -O0 on gcc, but hangs forever with gcc and -O3. It also exits immediately if I remove the [[gnu::pure]] function attribute, even though the function does not modify global state. The program is…
Omnifarious
  • 54,333
  • 19
  • 131
  • 194
2
votes
2 answers

using function attributes to store results for lazy (potential) processing

I'm doing some collision detection and I would very much like to use the same function in two different contexts. In one context, I would like for it to be something like def detect_collisions(item, others): return any(collides(item, other) for…
aaronasterling
  • 68,820
  • 20
  • 127
  • 125
2
votes
1 answer

LLVM how to set Attributes::NoUnwind to Function?

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 Attrs; …
kpdev
  • 610
  • 1
  • 7
  • 20
1
vote
1 answer

gcc 12 suggesting to add the "pure" attribute

I have written a container class very similar to std::vector. It has a size() member function, which I declared noexcept, const and constexpr. class my_vector { ... constexpr auto size() const noexcept -> size_type { assert(stride_…
alfC
  • 14,261
  • 4
  • 67
  • 118
1
vote
1 answer

Is function declared as __attribute__ ((pure)) allowed to return newly constructed std::string

In gnu world of C/C++ with GCC compiler there is Common function attribute "pure" (which is like "const" attribute, but with less restrictions): Many functions have no effects except the return value and their return value depends only on the…
osgx
  • 90,338
  • 53
  • 357
  • 513
1
vote
2 answers

Is it possible to have a make a generic method which can take the place of three methods with a System.Data.Linq.Mapping.FunctionAttribute?

I have three methods in my datacontext class which all call slightly different stored procedures having different behaviours; APPEND, UPDATE, OVERWRITE. However all three methods have in essence the same code. The only difference is the "Name"…
Dib
  • 2,001
  • 2
  • 29
  • 45
0
votes
2 answers

How to mark a function with return type not to return?

If I don't return anything in a function which returns something, compiler will warn about the function is not returning anything. But If I call abort() in the function, compiler won't warn. How can I mark my own function like this.
eonil
  • 83,476
  • 81
  • 317
  • 516
0
votes
2 answers

In Python, how can I use a function attribute as a function?

In Python, you could define a function attribute "call_count" such that: def counter(func): def inner(*args): inner.call_count+= 1 return func(*args) inner.call_count= 0 return inner def sum(a, b, c): return…
0
votes
0 answers

Mark function to be used only under lock

I'm writing a linux kernel driver and I have a function which MUST be called under lock, and I want to make sure no one will use it without acquiring the lock. This function is called many times from different functions which acquire the lock prior…
0
votes
0 answers

Python scipy.optimize.f_min_l_bfgs_b algorithm: how to have extra outputs?

I am using L-BFGS-B optimizer from Scipy package. Here is the documentation. My code has the following structure. obj_func is the objective function that is used to minimize "a". In order to do so, obj_func should only return "a". Question: Is…
zcadqe
  • 937
  • 2
  • 13
  • 20