On 06/12/2018 03:37 PM, Jeff Law wrote:
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.

Agreed.  Discarding invalid built-in declarations (in addition
to issuing a warning) would have prevented this bug as well as
bug 86202.  I'm working on a patch to at least warn on these
bad declarations if not drop them altogether (as GCC already
does some others).  This is bug 86125.

Martin

Reply via email to