[cfe-dev] Clang happily ignoring an attribute

via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 19 22:14:13 PDT 2018


On Wed, Apr 18, 2018 at 2:00 AM, via cfe-dev <cfe-dev at lists.llvm.org> 
wrote:
>
> Hello everyone,
>
> currently I'm checking if some functions are inlined with clang or not. 
Because of that I have a lot of unused variables storing return values - 
but clang optimizes them away including the function. Even "volatile" 
didn't stopped Clang from doing so. So I tried using the GCC attribute 
"used". But clang just responses:
> 1>main.cpp(9,23): warning : 'used' attribute ignored 
[-Wignored-attributes]
> 1>          void* __attribute__((used)) adr = _ReturnAddress();
>
>
> Why is clang doing this? And how can I prevent him easily from 
optimizing my values without referencing them?

It's hard to say for certain without a bit more information, but my
guess is that your variable does not have static storage duration. For
instance, the used attribute does not apply to local variables unless
they're also declared static.

HTH!

~Aaron

Hey Aaron,

what is HTH? :0

Ohhh! Thank you! This was the problem. I forgot to add "static". Sorry!

Kind greetings,
Björn

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, 
USt.ID-Nr. DE 114 165 789
Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, 
Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180420/6aa510fe/attachment.html>


More information about the cfe-dev mailing list