[cfe-dev] Clang happily ignoring an attribute

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 20 06:00:30 PDT 2018

On Fri, Apr 20, 2018 at 1:14 AM,  <bjoern.gaier at horiba.com> wrote:
> 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

"Hope This Helps" :-)

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

Glad to help!


More information about the cfe-dev mailing list