020-fix_pr61144.patch 828 B

123456789101112131415161718192021
  1. --- a/gcc/varpool.c
  2. +++ b/gcc/varpool.c
  3. @@ -329,8 +329,16 @@ ctor_for_folding (tree decl)
  4. /* Variables declared 'const' without an initializer
  5. have zero as the initializer if they may not be
  6. - overridden at link or run time. */
  7. - if (!DECL_INITIAL (real_decl)
  8. + overridden at link or run time.
  9. +
  10. + It is actually requirement for C++ compiler to optimize const variables
  11. + consistently. As a GNU extension, do not enfore this rule for user defined
  12. + weak variables, so we support interposition on:
  13. + static const int dummy = 0;
  14. + extern const int foo __attribute__((__weak__, __alias__("dummy")));
  15. + */
  16. + if ((!DECL_INITIAL (real_decl)
  17. + || (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
  18. && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
  19. return error_mark_node;