aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2021-10-26 14:38:11 -0600
committerMartin Sebor <msebor@redhat.com>2021-10-26 16:53:23 -0600
commit9a27acc30a34b7854db32eac562306cebac6fa1e (patch)
tree50aec5b68739f53fc25c813f8ab5c029167141dd /gcc/testsuite
parent88b504b7a8c5affb0ffa97990d22af2b199e36ed (diff)
downloadgcc-9a27acc30a34b7854db32eac562306cebac6fa1e.zip
gcc-9a27acc30a34b7854db32eac562306cebac6fa1e.tar.gz
gcc-9a27acc30a34b7854db32eac562306cebac6fa1e.tar.bz2
Make full use of context-sensitive ranges in access warnings.
gcc/ChangeLog: * builtins.c (check_strncat_sizes): Pass access_data ctor additional arguments. (expand_builtin_memcmp): Move code to gimple-ssa-warn-access.cc. (expand_builtin_fork_or_exec): Same. * gimple-array-bounds.cc (array_bounds_checker::check_mem_ref): Pass compute_objsize additional arguments. (inbounds_memaccess_p): Same. (array_bounds_checker::check_array_bounds): Add an assert. Stash statement in a member. (check_array_bounds_dom_walker::before_dom_children): Same. * gimple-array-bounds.h (array_bounds_checker::m_stmt): New member. * gimple-ssa-sprintf.c (get_destination_size): Add an argument. (handle_printf_call): Pass a new argument. * gimple-ssa-warn-access.cc (get_size_range): Add an argument. (check_access): Add an argument and pass it along to callees. (check_read_access): Make a member function. (pass_waccess::check_strcat): Pass access_data ctor additional arguments. (pass_waccess::check_strncat): Same. (pass_waccess::check_stxcpy): Same. (pass_waccess::check_stxncpy): Same. (pass_waccess::check_strncmp): Same. (pass_waccess::check_read_access): Same. (pass_waccess::check_builtin): Same. (pass_waccess::maybe_check_access_sizes): Same. (pass_waccess::maybe_check_dealloc_call): Same. * gimple-ssa-warn-access.h (check_read_access): Declare a new member function. * pointer-query.cc (compute_objsize_r): Add an argument. (gimple_call_return_array): Same. (gimple_call_alloc_size): Same. (access_ref::access_ref): Same. (access_ref::get_ref): Same. (pointer_query::get_ref): Same. (handle_min_max_size): Pass an arguments to callees. (handle_array_ref): Add an argument. (handle_mem_ref): Same. (compute_objsize): Same. * pointer-query.h (struct access_ref): Adjust signatures. (struct access_data): Same. (gimple_call_alloc_size): Add an argument. (gimple_parm_array_size): Same. (compute_objsize): Same. * tree-ssa-strlen.c (strlen_pass::adjust_last_stmt): Pass an additional argument to compute_objsize. (strlen_pass::maybe_warn_overflow): Same. (maybe_diag_stxncpy_trunc): Same. gcc/testsuite/ChangeLog: * gcc.dg/Wstringop-overflow-22.c: Correct typos. * gcc.dg/Wstringop-overflow-81.c: New test. libstdc++-v3/ChangeLog: * testsuite/21_strings/basic_string/capacity/1.cc: Also suppress -Wstringop-overread. * testsuite/27_io/filesystem/path/factory/u8path-char8_t.cc: Same.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/gcc.dg/Wstringop-overflow-22.c11
-rw-r--r--gcc/testsuite/gcc.dg/Wstringop-overflow-81.c38
2 files changed, 43 insertions, 6 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-22.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-22.c
index 8eaaa71..764b199 100644
--- a/gcc/testsuite/gcc.dg/Wstringop-overflow-22.c
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-22.c
@@ -260,13 +260,12 @@ T (puts_unlocked, a); // { dg-warning "missing terminating nul" "puts_unlo
// Exerise exec functions.
T (execl, a, s, NULL); // { dg-warning "missing terminating nul" "execl" }
-T (execl, a, s, NULL); // { dg-warning "missing terminating nul" "execl" }
-T (execle, a, s, NULL, NULL); // { dg-warning "missing terminating nul" "execl" }
-T (execlp, a, s, NULL); // { dg-warning "missing terminating nul" "execl" }
+T (execle, a, s, NULL, NULL); // { dg-warning "missing terminating nul" "execle" }
+T (execlp, a, s, NULL); // { dg-warning "missing terminating nul" "execlp" }
-T (execv, a, &d); // { dg-warning "missing terminating nul" "execl" }
-T (execve, a, &d, &d); // { dg-warning "missing terminating nul" "execl" }
-T (execvp, a, &d); // { dg-warning "missing terminating nul" "execl" }
+T (execv, a, &d); // { dg-warning "missing terminating nul" "execv" }
+T (execve, a, &d, &d); // { dg-warning "missing terminating nul" "execve" }
+T (execvp, a, &d); // { dg-warning "missing terminating nul" "execvp" }
T (gettext, a); // { dg-warning "missing terminating nul" "gettext" }
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-81.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-81.c
new file mode 100644
index 0000000..e8bc327
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-81.c
@@ -0,0 +1,38 @@
+/* Verify that -Wstringop-overflow uses context-sensitive range info
+ even at -O0.
+ { dg-do compile }
+ { dg-options "-O0 -Wall" } */
+
+extern void* memset (void*, int, __SIZE_TYPE__);
+
+char a[8];
+
+void warn_offset_range (int i)
+{
+ if (i < 4)
+ i = 4;
+ memset (a + i, 0, 5); // { dg-warning "writing 5 bytes into a region of size 4 " }
+}
+
+void warn_size_range (int i, int n)
+{
+ if (n < 5)
+ n = 5;
+
+ memset (a + 4, 1, n); // { dg-warning "writing between 5 and \\d+ bytes into a region of size 4 " }
+}
+
+void warn_offset_and_size_range (int i, int n)
+{
+ if (n < 5)
+ n = 5;
+
+ if (i < 4)
+ {
+ if (n < 9)
+ n = 9;
+ memset (a + i, 1, n); // { dg-warning "writing between 9 and \\d+ bytes into a region of size 8 " }
+ }
+ else
+ memset (a + i, 0, n); // { dg-warning "writing between 5 and \\d+ bytes into a region of size 4 " }
+}