Do FlatBuffers somehow avoid strict aliases?

I recently watched the FlatBuffers library. I wanted to evaluate it for use in my project. Having looked at flatbuffers.h , I wonder if there is a violation of strict anti-aliasing rule , and if this explains a strict alias, can someone explain how this is done?

In previous projects, I learned this rule, but optimization gives subtle errors that are hard to find. I used the new layout operator to avoid using compiler flags to account for this.

References:

+4
source share
1 answer

Currently, reading FlatBuffer is completely read-only, so the compiler cannot accept pointer aliases, and this should not cause any problems.

Writing a FlatBuffer is perhaps more complicated, but here, too, each piece of memory is affected only once by a single pointer and is never read, except for comparing vtable in EndTable()(which are read memcmp()).

Then, theoretically, if you first build a FlatBuffer and then read it right away, it will be able to optimize the write and read code and make “evil” optimizations of the kind that Linus referred to in your link above (pretending to never write).

The code is pure wrt -fstrict-aliasing -Wstrict-aliasing=3, not something that gives any kind of guarantee.

- , , - , ( -fno-strict-aliasing:), .

+3

Source: https://habr.com/ru/post/1545396/


All Articles