diff options
author | Martin Sebor <msebor@redhat.com> | 2020-08-28 13:13:28 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2020-08-28 13:18:28 -0600 |
commit | d14c547abd484d3540b692bb8048c4a6efe92c8b (patch) | |
tree | d3ba650daec2ba98a7b37f8f98ca5ef42c994ae9 /gcc/doc | |
parent | 26c24398d3615aef43e599f87911c1ecc3bd2841 (diff) | |
download | gcc-d14c547abd484d3540b692bb8048c4a6efe92c8b.zip gcc-d14c547abd484d3540b692bb8048c4a6efe92c8b.tar.gz gcc-d14c547abd484d3540b692bb8048c4a6efe92c8b.tar.bz2 |
Add -Wstringop-overread for reading past the end by string functions.
gcc/ChangeLog:
* attribs.c (init_attr_rdwr_indices): Use global access_mode.
* attribs.h (struct attr_access): Same.
* builtins.c (fold_builtin_strlen): Add argument.
(compute_objsize): Declare.
(get_range): Declare.
(check_read_access): New function.
(access_ref::access_ref): Define ctor.
(warn_string_no_nul): Add arguments. Handle -Wstrintop-overread.
(check_nul_terminated_array): Handle source strings of different
ranges of sizes.
(expand_builtin_strlen): Remove warning code, call check_read_access
instead. Declare locals closer to their initialization.
(expand_builtin_strnlen): Same.
(maybe_warn_for_bound): New function.
(warn_for_access): Remove argument. Handle -Wstrintop-overread.
(inform_access): Change argument type.
(get_size_range): New function.
(check_access): Remove unused arguments. Add new arguments. Handle
-Wstrintop-overread. Move warning code to helpers and call them.
Call check_nul_terminated_array.
(check_memop_access): Remove unnecessary and provide additional
arguments in calls.
(expand_builtin_memchr): Call check_read_access.
(expand_builtin_strcat): Remove unnecessary and provide additional
arguments in calls.
(expand_builtin_strcpy): Same.
(expand_builtin_strcpy_args): Same. Avoid testing no-warning bit.
(expand_builtin_stpcpy_1): Remove unnecessary and provide additional
arguments in calls.
(expand_builtin_stpncpy): Same.
(check_strncat_sizes): Same.
(expand_builtin_strncat): Remove unnecessary and provide additional
arguments in calls. Adjust comments.
(expand_builtin_strncpy): Remove unnecessary and provide additional
arguments in calls.
(expand_builtin_memcmp): Remove warning code. Call check_access.
(expand_builtin_strcmp): Call check_access instead of
check_nul_terminated_array.
(expand_builtin_strncmp): Handle -Wstrintop-overread.
(expand_builtin_fork_or_exec): Call check_access instead of
check_nul_terminated_array.
(expand_builtin): Same.
(fold_builtin_1): Pass additional argument.
(fold_builtin_n): Same.
(fold_builtin_strpbrk): Remove calls to check_nul_terminated_array.
(expand_builtin_memory_chk): Add comments.
(maybe_emit_chk_warning): Remove unnecessary and provide additional
arguments in calls.
(maybe_emit_sprintf_chk_warning): Same. Adjust comments.
* builtins.h (warn_string_no_nul): Add arguments.
(struct access_ref): Add member and ctor argument.
(struct access_data): Add members and ctor.
(check_access): Adjust signature.
* calls.c (maybe_warn_nonstring_arg): Return an indication of
whether a warning was issued. Issue -Wstrintop-overread instead
of -Wstringop-overflow.
(append_attrname): Adjust to naming changes.
(maybe_warn_rdwr_sizes): Same. Remove unnecessary and provide
additional arguments in calls.
* calls.h (maybe_warn_nonstring_arg): Return bool.
* doc/invoke.texi (-Wstringop-overread): Document new option.
* gimple-fold.c (gimple_fold_builtin_strcpy): Provide an additional
argument in call.
(gimple_fold_builtin_stpcpy): Same.
* tree-ssa-uninit.c (maybe_warn_pass_by_reference): Adjust to naming
changes.
* tree.h (enum access_mode): New type.
gcc/c-family/ChangeLog:
* c.opt (Wstringop-overread): New option.
gcc/testsuite/ChangeLog:
* c-c++-common/Warray-bounds-7.c: Adjust expected warnings.
* c-c++-common/Wrestrict.c: Remove xfail.
* c-c++-common/attr-nonstring-3.c: Adjust text of expected warnings.
* c-c++-common/attr-nonstring-6.c: Suppress -Wstringop-overread
instead of -Wstringop-overflow.
* c-c++-common/attr-nonstring-8.c: Adjust text of expected warnings.
* g++.dg/torture/Wsizeof-pointer-memaccess1.C: Also suppress
-Wstringop-overread.
* g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same.
* gcc.dg/Warray-bounds-39.c: Adjust expected warnings.
* gcc.dg/Warray-bounds-40.c: Also suppress -Wstringop-overread.
* gcc.dg/Warray-bounds-58.c: Remove xfail. Also expect
-Wstringop-overread. Adjust text of expected warnings.
* gcc.dg/Wsizeof-pointer-memaccess1.c: Also suppress
-Wstringop-overread.
* gcc.dg/Wstringop-overflow-22.c: Adjust text of expected warnings.
* gcc.dg/Wstringop-overflow-33.c: Expect -Wstringop-overread.
* gcc.dg/Wstringop-overflow-9.c: Expect -Wstringop-overread.
* gcc.dg/attr-nonstring-2.c: Adjust text of expected warnings.
* gcc.dg/attr-nonstring-3.c: Same.
* gcc.dg/attr-nonstring-4.c: Same.
* gcc.dg/attr-nonstring.c: Expect -Wstringop-overread.
* gcc.dg/builtin-stringop-chk-5.c: Adjust comment.
* gcc.dg/builtin-stringop-chk-8.c: Enable -Wstringop-overread instead
of -Wstringop-overflow.
* gcc.dg/pr78902.c: Also expect -Wstringop-overread.
* gcc.dg/pr79214.c: Adjust text of expected warnings.
* gcc.dg/strcmpopt_10.c: Suppress valid -Wno-stringop-overread.
* gcc.dg/strlenopt-57.c: Also expect -Wstringop-overread.
* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Also suppress valid
-Wno-stringop-overread.
* gcc.dg/tree-ssa/builtins-folding-gimple-ub.c: Same.
* gcc.dg/uninit-33.c: Same.
* gcc.dg/warn-strnlen-no-nul-2.c: Adjust text of expected warning.
* gcc.dg/warn-strnlen-no-nul.c: Same.
* gcc.target/i386/strcmpopt_6.c: Suppress -Wstringop-overread.
* gcc.dg/Wstringop-overread-2.c: New test.
* gcc.dg/Wstringop-overread.c: New test.
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/invoke.texi | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c999242..5d29a7f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -366,7 +366,8 @@ Objective-C and Objective-C++ Dialects}. -Wstack-protector -Wstack-usage=@var{byte-size} -Wstrict-aliasing @gol -Wstrict-aliasing=n -Wstrict-overflow -Wstrict-overflow=@var{n} @gol -Wstring-compare @gol --Wstringop-overflow=@var{n} -Wno-stringop-truncation @gol +-Wno-stringop-overflow -Wno-stringop-overread @gol +-Wno-stringop-truncation @gol -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}malloc@r{]} @gol -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum @gol -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol @@ -6754,6 +6755,7 @@ void f (char *d) @option{-Wstring-compare} is enabled by @option{-Wextra}. +@item -Wno-stringop-overflow @item -Wstringop-overflow @itemx -Wstringop-overflow=@var{type} @opindex Wstringop-overflow @@ -6795,6 +6797,15 @@ const char* f (enum Color clr) Option @option{-Wstringop-overflow=2} is enabled by default. +@item -Wno-stringop-overread +@opindex Wstringop-overread +@opindex Wno-stringop-overread +Warn for calls to string manipulation functions such as @code{memchr}, +@code{strcpy} that are determined to read past the end of the source +sequence. + +Option @option{-Wstringop-overread} is enabled by default. + @table @gcctabopt @item -Wstringop-overflow @itemx -Wstringop-overflow=1 @@ -7502,8 +7513,12 @@ This warning is also enabled by @option{-Wshadow=local}. Warn whenever an object is defined whose size exceeds @var{byte-size}. @option{-Wlarger-than=}@samp{PTRDIFF_MAX} is enabled by default. Warnings controlled by the option can be disabled either by specifying -@var{byte-size} of @samp{SIZE_MAX} or more or by -@option{-Wno-larger-than}. +@var{byte-size} of @samp{SIZE_MAX} or more or by @option{-Wno-larger-than}. + +Also warn for calls to bounded functions such as @code{memchr} or +@code{strnlen} that specify a bound greater than the largest possible +object, which is @samp{PTRDIFF_MAX} bytes by default. These warnings +can only be disabled by @option{-Wno-larger-than}. @item -Wno-larger-than @opindex Wno-larger-than |