Hi, The patch below addresses PR68270. could you please take a look?
2016-11-25 Alexander Ivchenko <aivch...@gmail.com> * c-family/c.opt (flag_chkp_flexible_struct_trailing_arrays): Add new option. * tree-chkp.c (chkp_parse_array_and_component_ref): Forbid narrowing when chkp_parse_array_and_component_ref is used and the ARRAY_REF points to an array in the end of the struct. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 7d8a726..e45d6a2 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1166,6 +1166,11 @@ C ObjC C++ ObjC++ LTO RejectNegative Report Var(flag_chkp_narrow_to_innermost_ar Forces Pointer Bounds Checker to use bounds of the innermost arrays in case of nested static arryas access. By default outermost array is used. +fchkp-flexible-struct-trailing-arrays +C ObjC C++ ObjC++ LTO RejectNegative Report Var(flag_chkp_flexible_struct_trailing_arrays) +Allow Pointer Bounds Checker to treat all trailing arrays in structures as +possibly flexible. + fchkp-optimize C ObjC C++ ObjC++ LTO Report Var(flag_chkp_optimize) Init(-1) Allow Pointer Bounds Checker optimizations. By default allowed diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 2769682..40f99c3 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3425,7 +3425,9 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr, if (flag_chkp_narrow_bounds && !flag_chkp_narrow_to_innermost_arrray && (!last_comp - || chkp_may_narrow_to_field (TREE_OPERAND (last_comp, 1)))) + || (chkp_may_narrow_to_field (TREE_OPERAND (last_comp, 1)) + && !(flag_chkp_flexible_struct_trailing_arrays + && array_at_struct_end_p (var))))) { comp_to_narrow = last_comp; break;