On 06/12/2018 03:29 PM, Martin Sebor wrote:
> Declaring strlen() to return a pointer instead of size_t
> and then calling the function can result in an ICE due to
> both gimple-fold and tree-ssa-strlen assuming the function
> necessarily returns an integer.
> 
> As luck would have it, the incompatible declaration isn't
> detected by -Wbuiltin-declaration-mismatch (bug 86125), nor
> apparently even by gimple_builtin_call_types_compatible_p(),
> and so the invalid declaration makes its way where it isn't
> expected.
> 
> The attached patch avoids the ICE by removing the unsafe
> assumption from both the folder and the strlen pass.
> 
> Martin
> 
> gcc-86114.diff
> 
> 
> PR tree-optimization/86114 - ICE in gimple_fold_builtin_strlen with an 
> invalid call to strnlen
> 
> gcc/testsuite/ChangeLog:
> 
>       PR tree-optimization/86114
>       * gcc.dg/pr86114.c: New test.
> 
> gcc/ChangeLog:
> 
>       PR tree-optimization/86114
>       * gimple-fold.c (gimple_fold_builtin_strlen): Only handle LHS
>       of integer types.
>       * tree-ssa-strlen.c (maybe_set_strlen_range): Same.
OK.  However ISTM that catching this earlier would be advisable.

jeff

Reply via email to