This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] add attribute nonstring
- From: Siddhesh Poyarekar <siddhesh at gotplt dot org>
- To: Martin Sebor <msebor at gmail dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 27 Nov 2017 16:35:06 +0530
- Subject: Re: [PATCH] add attribute nonstring
- Authentication-results: sourceware.org; auth=none
- References: <d0432148-24d3-baaa-faf6-b00c33e45103@gmail.com>
On Friday 10 November 2017 11:01 PM, Martin Sebor wrote:
> diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/gnu/bits/utmp.h
> index 2ee11cb..d4885f3 100644
> --- a/sysdeps/gnu/bits/utmp.h
> +++ b/sysdeps/gnu/bits/utmp.h
> @@ -59,9 +59,13 @@ struct utmp
> {
> short int ut_type; /* Type of login. */
> pid_t ut_pid; /* Process ID of login process. */
> + __NONSTRING
> char ut_line[UT_LINESIZE]; /* Devicename. */
> + __NONSTRING
> char ut_id[4]; /* Inittab ID. */
> + __NONSTRING
> char ut_user[UT_NAMESIZE]; /* Username. */
> + __NONSTRING
> char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */
> struct exit_status ut_exit; /* Exit status of a process marked
> as DEAD_PROCESS. */
This breaks builds with the latest gcc since your commit to warn on
non-string arguments to strlen:
commit 0c45740b611e0930073eeae00422a17c62c2d983
Author: msebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue Nov 21 20:01:58 2017 +0000
PR tree-optimization/82945 - add warning for passing non-strings to
functions that expect string arguments
gcc/ChangeLog:
PR tree-optimization/82945
* builtins.c (expand_builtin_strlen): Call maybe_warn_nonstring_arg.
* calls.h (maybe_warn_nonstring_arg): Declare new function.
* calls.c (get_attr_nonstring_decl, maybe_warn_nonstring_arg): New
functions.
(initialize_argument_information): Call maybe_warn_nonstring_arg.
* calls.h (get_attr_nonstring_decl): Declare new function.
* doc/extend.texi (attribute nonstring): Update.
* gimple-fold.c (gimple_fold_builtin_strncpy): Call
get_attr_nonstring_decl and handle it.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Same. Improve
detection of nul-termination.
(strlen_to_stridx): Change to a pointer.
(handle_builtin_strlen, handle_builtin_stxncpy): Adjust.
(pass_strlen::execute): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/82945
* c-c++-common/Wstringop-truncation-2.c: New test.
* c-c++-common/Wstringop-truncation.c: Adjust.
* c-c++-common/attr-nonstring-2.c: Adjust.
* c-c++-common/attr-nonstring-3.c: New test.
Siddhesh