Questions tagged [function-attributes]
The function-attributes tag has no usage guidance.
function-attributes
39
questions
4
votes
0
answers
94
views
Is there such a thing as "function attribute correctness"?
Ok so C23 adds function attributes to the language but I'm not sure if anyone actually considered how they are supposed to be used. Consider this example:
[[deprecated]] int foo () { return 0; }
[[...
3
votes
1
answer
53
views
What's an implementation required to do upon seeing unknown attributes?
C2X has introduced "Attribute specifier sequence", which can be of these forms:
1) standard attribute, such as [[fallthrough]]
2) attribute with a namespace, such as [[gnu::unused]]
3) ...
2
votes
1
answer
725
views
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-...
3
votes
4
answers
667
views
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 ...
1
vote
1
answer
322
views
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 ...
4
votes
0
answers
1k
views
How to get custom attributes in LLVM Pass
I implemented a custom attribute in clang as described in the official manual:
How to add an attribute in Clang
I added a definition to include/clang/Basic/Attr.td
def attr : InheritableAttr {
let ...
0
votes
2
answers
152
views
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....
15
votes
3
answers
614
views
GCC/Clang function attributes per template instantiation
I have some hand-vectorized C++ code that I'm trying to make a distribute-able binary for via function multiversioning. Since the code uses SIMD intrinsics for different instruction sets (SSE2, AVX2, ...
2
votes
2
answers
686
views
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, ...
3
votes
1
answer
105
views
Pure version of `std.format.format!`?
I'd like to convert a double to a string in a pure function. I'm confused as to why this isn't pure:
wstring fromNumber(double n) pure {
import std.format;
return std.format.format!("%s"w)(n);...
2
votes
2
answers
336
views
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 <stdio.h>
static int a = 1;
...
3
votes
0
answers
558
views
A more standard __attribute__((warning("msg"))
In my C++ library, I have a function that is still there, 1) for debugging 2) for small operations.
The function is basically a very slow fallback of more efficient versions.
(think of a loop of ...
-2
votes
1
answer
123
views
function attribute lifespan
I'm writing a memoization of a function and I want to store an attribute in the function object.
Will the function attribute be available for the lifespan of the process? if not how can I achieve such ...
2
votes
2
answers
1k
views
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 ...
2
votes
3
answers
692
views
gcc linker extension __attribute__((constructor)) causes crash in main()
First I've a singleton.cpp file to build a singleton object, and declare instance using attribute((constructor))
#include<iostream>
using namespace std;
class singleton{
public:
singleton(){...