https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
The difference between success and failure is due to this bit of code in
symtab.c:

  /* With !flag_delete_null_pointer_checks we assume that symbols may
     bind to NULL. This is on by default on embedded targets only.

     Otherwise all non-WEAK symbols must be defined and thus non-NULL or
     linking fails.  Important case of WEAK we want to do well are comdats.
     Those are handled by later check for definition.

     When parsing, beware the cases when WEAK attribute is added later.  */
  if (!DECL_WEAK (decl)
      && flag_delete_null_pointer_checks)
    {
      refuse_visibility_changes = true;
      return true;
    }

But the address of a static local variable can never be null so the test above
is unnecessarily restrictive.  The following patch relaxes the test, letting
GCC accept the test case even with -fsanitize=undefined.  I didn't spot any
obvious failures in the test suite with it.

--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1937,7 +1937,8 @@ symtab_node::nonzero_address ()

      When parsing, beware the cases when WEAK attribute is added later.  */
   if (!DECL_WEAK (decl)
-      && flag_delete_null_pointer_checks)
+      && (flag_delete_null_pointer_checks
+         || (TREE_STATIC (decl) && !DECL_EXTERNAL (decl))))
     {
       refuse_visibility_changes = true;
       return true;

Reply via email to