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

--- Comment #13 from qinzhao at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #12)
> Created attachment 54547 [details]
> gcc13-pr108894.patch
> 
> Untested fix.

several comments on the patch:

1. should the documentation of -fsanitize=bounds and -fsanitize=strict-bounds
be updated to reflect the interaction with -fstrict-flex-arrays=N?
2. there are several routines in c-decl.cc:
 static bool  flexible_array_member_type_p (const_tree type);
 static bool  one_element_array_type_p (const_tree type);
 static bool  zero_length_array_type_p (const_tree type);

can they be generalized  as well to be used in the routine 
"ubsan_instrument_bounds" to check for [], [0], or [1]? (in the patch lines
from 405 to 442). 
3. could you add comments for lines (I guess they are for [0])?

370       if (!bound)
371         bound = fold_build2 (PLUS_EXPR, TREE_TYPE (bound), bound,   371    
    {
372                              build_int_cst (TREE_TYPE (bound), 1)); 372    
      if (!c_dialect_cxx ()
373               && COMPLETE_TYPE_P (type)
374               && integer_zerop (TYPE_SIZE (type)))
375             bound = build_int_cst (TREE_TYPE (TYPE_MIN_VALUE (domain)),
-1);
376           else
377             return NULL_TREE;
378         }

Reply via email to