https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89698
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P2 Status|UNCONFIRMED |NEW Known to work| |6.5.0 Keywords| |wrong-code Last reconfirmed| |2019-03-13 Ever confirmed|0 |1 Summary|Run-time error due to |[7/8/9 Regression] Run-time |optimization of field |error due to optimization |access after cast at |of field access after cast |-Os/-O2 and higher |at -Os/-O2 and higher Target Milestone|--- |7.5 Known to fail| |7.1.0, 9.0 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Confirmed. GCC 6 seems to work. The FE already folds the test to if ((long unsigned int) BIT_FIELD_REF <*(struct A *) vp, 64, 64> == 8589934593) rewriting the testcase to int test(void) { int res; B b(2); A* bp = &b; void* vp = dynamic_cast<void*>(bp); if (((A*)vp)->x == 1) if (((B*)vp)->y == 2) return 1; // PASS return 0; // FAIL } makes it PASS. So I suspect this BIT_FIELD_REF doesn't tell the truth. Note the IL looks odd as well, possibly from the dynamic_cast which looks fishy to me.