https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108552
--- Comment #40 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jan Hubicka from comment #39) > I was wonering if we should not provide flag to turn all counts > volatile. That way we will still have race conditions on their updates > (and it would be chepaer than atomic) but we won't run into such wrong > code issues nor large profile mismatches. Yes, see above. Or a mode in which we would just avoid hoisting and sinking the gcov vars but keep them non-volatile. Or both. But I guess it would be nice to get Vlad's patch into trunk and release branches for now (perhaps with an extra check for startswith "__gcov" on DECL_NAME, so that we don't do it for the Fortran tokens). As for the patch, just small nits, I think get_base_address returns always non-NULL, so it could be if (tree expr = MEM_EXPR (res)) { expr = get_base_address (expr); if (VAR_P (expr) && DECL_NONALIASED (expr) && DECL_NAME (expr)) { const char *name = IDENTIFIER_POINTER (DECL_NAME (expr)); /* Don't reread coverage counters from memory, if single update model is used in threaded code, other threads could change the counters concurrently. See PR108552. */ if (startswith (name, "__gcov")) return x; } }