__attribute__ ((no_check_memory_usage)) in template member functions?
Andrew Morton
morton@nortelnetworks.com
Wed Mar 15 06:42:00 GMT 2000
Hi, George.
"George T. Talbot" wrote:
>
> I'm using gcc (g++ actually) 2.95.2 running on Linux on a Pentium II (x86). I
> have a test program, and I want to compile it with -fcheck-memory-usage.
If you're simply using C then the _only_ way to get
__attribute__((no_check_memory_usage)) to work is by using it in the
function prototype:
===================
int x;
void foo(void) __attribute__((no_check_memory_usage));
void foo(void)
{
x = 1;
}
void bar(void)
{
x = 2;
}
===================
Here, checking is suppressed for foo() and not bar().
However this cannot be exploited for inline functions:
===========================
class thing
{
public:
void release(void);
void release(void)
{
}
};
main()
{
thing t;
}
===========================
t1.cc:7: `thing::release ()' has already been declared in `thing'
You can't forward declare methods in this manner.
The only way I can get this to work is with:
====================================
int x;
class thing
{
public:
void release1(void) __attribute__((no_check_memory_usage));
void release2(void);
};
void thing::release1(void)
{
x = 1;
}
void thing::release2(void)
{
x = 2;
}
void foo()
{
thing t;
t.release1();
t.release2();
}
====================================
Here, release1 has no memory checker calls. This may allow you to do
what you want to do.
If you make release1() an inline method with:
====================================
int x;
class thing
{
public:
inline void release1(void)
__attribute__((no_check_memory_usage));
void release2(void);
};
inline void thing::release1(void)
{
x = 1;
}
void thing::release2(void)
{
x = 2;
}
void foo()
{
thing t;
t.release1();
t.release2();
}
====================================
Then the checker calls _are_ produced, which is a bug.
One side thought: the only reason the -fcheck-memory-usage feature
checks for 'asm' code is that it can't generate memory checking code for
it. If you are comfortable with this then you can modify the compiler
so that it permits memory checking for asm-containing functions. If the
asm code touches memory then those accesses won't be checked or
recorded, but that's probably not a killer for you.
So it's a matter of finding the code which says "`asm' cannot be used in
function where memory usage is checked" and simply disabling it.
More information about the Gcc
mailing list