aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/misc.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-10-08 15:54:23 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-11-09 09:55:58 +0100
commit6b8b959675a3e14cfdd2145bd62e4260eb193765 (patch)
treeaaeb4a8542b28b6f9362a21c8127e1ecda9498a3 /gcc/fortran/misc.c
parentcc6b8cd9a21b363815998b11e5cc7529557a9ce5 (diff)
downloadgcc-6b8b959675a3e14cfdd2145bd62e4260eb193765.zip
gcc-6b8b959675a3e14cfdd2145bd62e4260eb193765.tar.gz
gcc-6b8b959675a3e14cfdd2145bd62e4260eb193765.tar.bz2
Convert strlen pass from evrp to ranger.
The following patch converts the strlen pass from evrp to ranger, leaving DOM as the last remaining user. No additional cleanups have been done. For example, the strlen pass still has uses of VR_ANTI_RANGE, and the sprintf still passes around pairs of integers instead of using a proper range. Fixing this could further improve these passes. Basically the entire patch is just adjusting the calls to range_of_expr to include context. The previous context of si->stmt was mostly empty, so not really useful ;-). With ranger we are now able to remove the range calculation from before_dom_children entirely. Just working with the ranger on-demand catches all the strlen and sprintf testcases with the exception of builtin-sprintf-warn-22.c which is due to a limitation of the sprintf code. I have XFAILed the test and documented what the problem is. On a positive note, these changes found two possible sprintf overflow bugs in the C++ and Fortran front-ends which I have fixed below. Tested on x86-64 Linux. gcc/ChangeLog: * tree-ssa-strlen.c (compare_nonzero_chars): Pass statement context to ranger. (get_addr_stridx): Same. (get_stridx): Same. (get_range_strlen_dynamic): Same. (handle_builtin_strlen): Same. (handle_builtin_strchr): Same. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Same. (handle_builtin_stxncpy_strncat): Same. (handle_builtin_memcpy): Same. (handle_builtin_strcat): Same. (handle_alloc_call): Same. (handle_builtin_memset): Same. (handle_builtin_string_cmp): Same. (handle_pointer_plus): Same. (count_nonzero_bytes_addr): Same. (count_nonzero_bytes): Same. (handle_store): Same. (fold_strstr_to_strncmp): Same. (handle_integral_assign): Same. (check_and_optimize_stmt): Same. (class strlen_dom_walker): Replace evrp with ranger. (strlen_dom_walker::before_dom_children): Remove evrp. (strlen_dom_walker::after_dom_children): Remove evrp. * gimple-ssa-warn-access.cc (maybe_check_access_sizes): Restrict sprintf output. gcc/cp/ChangeLog: * ptree.c (cxx_print_xnode): Add more space to pfx array. gcc/fortran/ChangeLog: * misc.c (gfc_dummy_typename): Make sure ts->kind is non-negative. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/builtin-sprintf-warn-22.c: XFAIL.
Diffstat (limited to 'gcc/fortran/misc.c')
-rw-r--r--gcc/fortran/misc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index e6402e8..a553e1e 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -284,7 +284,7 @@ gfc_dummy_typename (gfc_typespec *ts)
{
if (ts->kind == gfc_default_character_kind)
sprintf(buffer, "CHARACTER(*)");
- else if (ts->kind < 10)
+ else if (ts->kind >= 0 && ts->kind < 10)
sprintf(buffer, "CHARACTER(*,%d)", ts->kind);
else
sprintf(buffer, "CHARACTER(*,?)");