From: Martin Sebor Date: Thu, 4 Apr 2019 22:38:10 +0000 (+0000) Subject: PR middle-end/89957 - ICE calling strnlen with an int128_t bound in a known range X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1a9b15a7d76ee3ee2cd960698a84e34ec10c2bf0;p=gcc.git PR middle-end/89957 - ICE calling strnlen with an int128_t bound in a known range PR middle-end/89957 - ICE calling strnlen with an int128_t bound in a known range PR middle-end/89911 - [9 Regression] ICE in get_attr_nonstring_decl gcc/ChangeLog: PR middle-end/89957 PR middle-end/89911 * builtins.c (expand_builtin_strnlen): Make sure wi::ltu_p operands have the same precision since the function crashes otherwise. * calls.c (maybe_warn_nonstring_arg): Avoid assuming strnlen() call has non-zero arguments. gcc/testsuite/ChangeLog: PR middle-end/89957 PR middle-end/89911 * gcc.dg/Wstringop-overflow-13.c: New test. From-SVN: r270154 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bc97e199299..4e17249cda3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2019-04-04 Martin Sebor + + PR middle-end/89957 + PR middle-end/89911 + * builtins.c (expand_builtin_strnlen): Make sure wi::ltu_p operands + have the same precision since the function crashes otherwise. + * calls.c (maybe_warn_nonstring_arg): Avoid assuming strnlen() call + has non-zero arguments. + 2019-04-04 Martin Sebor PR middle-end/89934 diff --git a/gcc/builtins.c b/gcc/builtins.c index daf5830011f..d37d73fc4a0 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3151,7 +3151,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) return NULL_RTX; if (!TREE_NO_WARNING (exp) - && wi::ltu_p (wi::to_wide (maxobjsize), min) + && wi::ltu_p (wi::to_wide (maxobjsize, min.get_precision ()), min) && warning_at (loc, OPT_Wstringop_overflow_, "%K%qD specified bound [%wu, %wu] " "exceeds maximum object size %E", diff --git a/gcc/calls.c b/gcc/calls.c index 63c1bc52077..6b22e7a2315 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1555,7 +1555,10 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) if (TREE_NO_WARNING (exp) || !warn_stringop_overflow) return; + /* Avoid clearly invalid calls (more checking done below). */ unsigned nargs = call_expr_nargs (exp); + if (!nargs) + return; /* The bound argument to a bounded string function like strncpy. */ tree bound = NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc60f539a23..6954748fa15 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-04-04 Martin Sebor + + PR middle-end/89957 + PR middle-end/89911 + * gcc.dg/Wstringop-overflow-13.c: New test. + 2019-04-04 Martin Sebor PR middle-end/89934 @@ -8,7 +14,7 @@ PR rtl-optimization/89399 * gcc.c-torture/compile/pr89399.c: New test. - + 2019-04-04 Harald Anlauf PR fortran/89004 diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-13.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-13.c new file mode 100644 index 00000000000..bd513151cea --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-13.c @@ -0,0 +1,40 @@ +/* PR middle-end/89957 - ICE calling strnlen with an int128_t bound + in a known range + PR middle-end/89911 - ICE on a call with no arguments to strnlen + declared with no prototype + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +typedef __SIZE_TYPE__ size_t; + +extern size_t strnlen (); + +size_t f0 (void) +{ + return strnlen (); /* { dg-warning "too few arguments to built-in function 'strnlen'" } */ +} + +size_t f1 (const char *s) +{ + return strnlen (s); /* { dg-warning "too few arguments to built-in function 'strnlen'" } */ +} + +size_t f2 (const char *s) +{ + return strnlen (s, s); /* { dg-warning "\\\[-Wint-conversion]" } */ +} + +#if __SIZEOF_INT128__ == 16 + +size_t fi128 (const char *s, __int128_t n) +{ + if (n < 0) + n = 0; + + /* PR middle-end/89957 */ + return strnlen (s, n); /* { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" "int128" { target int128 } } */ +} + +#endif + +/* { dg-prune-output "\\\[-Wint-conversion]" } */