[cfe-dev] Clang happily ignoring an attribute

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 18 06:25:31 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

>
> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list