This code was wrongly devirtualized before:
A* a = new A; a->foo(); A* b = new(a) B; if (a == b) b->foo();
Now we insert barrier before comparing dynamic pointers.
Differential D32378
Insert invariant.group.barrier for pointers comparisons Prazek on Apr 21 2017, 2:52 PM. Authored by
Details
Diff Detail
Event Timeline
Comment Actions This is actually good catch, we also need to do it when inserting barrier in placement new. Comment Actions Don't add barrier if compared with nullptr. With this it reduces added Comment Actions Has it been discussed whether this is something to be addressed in the optimizer as opposed to the front-end?
Comment Actions The example that you showed is excellent. I didn't know that LLVM does the transformation with pointers and it clearly shows that we need the different approach. |
I think we need to do this regardless of optimization level -- if we LTO together a -O0 translation unit with a -O2 translation unit, we still need this protection for the comparisons in the -O0 TU.
(IIRC we chose to make -fstrict-vtable-pointers an IR-level ABI break, but we shouldn't do the same thing for optimization level.)