Discussion:
Volatile access is too expensive to silence a compiler warning when instrumentation is disabled
(too old to reply)
Matthias Schwarzott
2017-03-28 05:46:25 UTC
Permalink
Raw Message
Hi!

I appreciate that my request to get rid of the compiler warning about
VALGRIND_PRINTF was followed. See
https://bugs.kde.org/show_bug.cgi?id=356817.

But I am not so happy about the result:
Now in NVALGRIND case valgrind.h uses a volatile read in VALGRIND_PRINTF
and VALGRIND_PRINTF_BACKTRACE to silence the unused argument warning.

http://sourceware.org/git/?p=valgrind.git;a=blob;f=include/valgrind.h;h=dc7dca7b8b0f02978dc297718d362488ebf63da2;hb=HEAD#l6772

That means if one disables all instrumentation (maybe for performance
reasons) an unneeded volatile memory access remains in the code (of the
client application).

I vote for finding a different solution to tell the compiler to not show
a warning.

See https://bugs.kde.org/show_bug.cgi?id=358697

Regards
Matthias
Patrick J. LoPresti
2017-03-29 00:36:03 UTC
Permalink
Raw Message
In C++, you can just comment out the variable name in the argument list.

In C... Well, I did not know. So I searched and found:

http://stackoverflow.com/q/3599160/

It looks like a simple:

(void)format;

...should do the trick. And I suspect it will not emit any code.

- Pat
Patrick J. LoPresti
2017-03-29 00:41:46 UTC
Permalink
Raw Message
Sorry, should have read the bug report more carefully. I see you
already suggested this.

Of course this is the right fix. If some static analyzer complains,
that is a problem with the static analyzer and therefore irrelevant
(IMO).

- Pat
Post by Patrick J. LoPresti
In C++, you can just comment out the variable name in the argument list.
http://stackoverflow.com/q/3599160/
(void)format;
...should do the trick. And I suspect it will not emit any code.
- Pat
Julian Seward
2017-03-29 15:59:44 UTC
Permalink
Raw Message
Post by Patrick J. LoPresti
Sorry, should have read the bug report more carefully. I see you
already suggested this.
Of course this is the right fix. If some static analyzer complains,
that is a problem with the static analyzer and therefore irrelevant
(IMO).
I agree.

Matthias, if you are happy to test the simple "(void)format;" solution
with MSVC, then I am happy to commit it. Can you do that?

J

Loading...