Avoid bogus -Wuse-after-free in gcc 12 optimized builds
This seems to be https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104215 or at least similar to it, i.e. a known false positive that we unfortunately have to work around in this ugly way, by inserting a compiler-specific barrier. If we need such workarounds in other places, we should define a wxCOMPILE_BARRIER macro or something similar, but for now it seems to be only needed here.
This commit is contained in:
parent
74e7f5ccc9
commit
87836e0b97
1 changed files with 9 additions and 0 deletions
|
|
@ -519,6 +519,15 @@ public:
|
|||
const size_t idx = it - begin();
|
||||
const size_t after = end() - it;
|
||||
|
||||
// Unfortunately gcc 12 still complains about use-after-free even
|
||||
// though our code is correct because it actually optimizes it to be
|
||||
// wrong, with -O2 or higher, by moving the assignment above below the
|
||||
// call to reserve() below, so use this hack to avoid the warning with
|
||||
// it by preventing it from rearranging the code.
|
||||
#if wxCHECK_GCC_VERSION(12, 1)
|
||||
__asm__ __volatile__("":::"memory");
|
||||
#endif
|
||||
|
||||
reserve(size() + count);
|
||||
|
||||
// the place where the new element is going to be inserted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue