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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot 
gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the easiest way to fix this is inside instrument_mem_ref:ubsan.c check
TREE_OPERAND (base, 0) to see if it is ADDR_EXPR of a DECL_P then don't do the
check if non-weak.

Something like:
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index ba9adf0ad96..e66c430c7a2 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -1380,6 +1380,14 @@ instrument_mem_ref (tree mem, tree base,
gimple_stmt_iterator *iter,
   tree t = TREE_OPERAND (base, 0);
   if (!POINTER_TYPE_P (TREE_TYPE (t)))
     return;
+
+  /* For simple &decl don't instument this as it will be removed
+     later on. */
+  if (TREE_CODE (t) == ADDR_EXPR
+      && DECL_P (TREE_OPERAND (t, 0))
+      && DECL_WEAK (TREE_OPERAND (t, 0)))
+    return;
+
   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (base)) && mem != base)
     ikind = UBSAN_MEMBER_ACCESS;
   tree kind = build_int_cst (build_pointer_type (TREE_TYPE (base)), ikind);

Mine.

Reply via email to