M
M
Monnoroch2013-04-15 15:28:44
C++ / C#
Monnoroch, 2013-04-15 15:28:44

Is there a portable equivalent to __attribute__((noinline))?

Actually, function inlining should be prohibited: together with instruction reordering, it causes crashes. There is a special attribute for gcc, but I would not want to limit myself to gcc, I would like to compile the studio with a clang and an Intel compiler too. Is a subject possible?
So far the solution is:

#if defined(_MSC_VER)
#define NOINLINE __declspec(noinline)
#else
#define NOINLINE __attribute__ ((noinline))
#endif

But I'm not at all sure that this is cross-platform enough.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mayorovp, 2013-04-15
@mayorovp

In theory, this thing should be repaired by properly placed barriers ...

G
Gribozavr, 2013-04-15
@gribozavr

You have a problem somewhere else, and this is not a solution, but simply an avoidance of it.
There is no portable analogue in the standard. And Clang understands __attribute__((noinline)).
But if you really have all sorts of non-standard atomics there, then:
1. use standard atomics;
2. use ordered atomics;
3. use barriers (either for the processor, or only for the compiler asm volatile("":::"memory"););
4. find out why the compiler allows itself to do reordering around your assembler inserts or intrinsics. Compiler bug?
And then some link-time optimization will come and break everything again.
And yes, are you sure that you wrote your critical section correctly? And why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question