public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral
Date: Fri, 27 Feb 2015 16:43:00 -0000	[thread overview]
Message-ID: <bug-39438-4-7LIhwbLljo@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-39438-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-27
     Ever confirmed|0                           |1

--- Comment #10 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to D. Hugh Redelmeier from comment #6)
> If an arg is marked as a const char * (i.e. unchanging) and has the strftime
> format attribute, it should be accepted as if it were a literal strftime
> argument.  After all, the necessary checking would have been done at this
> routine's points of call.

The code that warns is this: gcc/c-family/c-format.c

    if (res.number_non_literal > 0)
      {
        /* Functions taking a va_list normally pass a non-literal format
           string.  These functions typically are declared with
           first_arg_num == 0, so avoid warning in those cases.  */
        if (!(format_types[info->format_type].flags & (int)
FMT_FLAG_ARG_CONVERT))
          {
            /* For strftime-like formats, warn for not checking the format
               string; but there are no arguments to check.  */
            warning_at (loc, OPT_Wformat_nonliteral,
                        "format not a string literal, format string not
checked");
          }

Thus, there is nothing checking the attributes of the caller. In the same file
there is this code:

                tree c;
                for (c = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
                     c;
                     c = TREE_CHAIN (c))
                  if (is_attribute_p ("format", TREE_PURPOSE (c))
                      && (decode_format_type (IDENTIFIER_POINTER
                                              (TREE_VALUE (TREE_VALUE (c))))
                          == info.format_type))
                    break;
                if (c == NULL_TREE)
                  {
                    /* Check if the current function has a parameter to which
                       the format attribute could be attached; if not, it
                       can't be a candidate for a format attribute, despite
                       the vprintf-like or vscanf-like call.  */
                    tree args;
                    for (args = DECL_ARGUMENTS (current_function_decl);
                         args != 0;
                         args = DECL_CHAIN (args))
                      {
                        if (TREE_CODE (TREE_TYPE (args)) == POINTER_TYPE
                            && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE
(args)))
                                == char_type_node))
                          break;
                      }
                    if (args != 0)
                      warning (OPT_Wsuggest_attribute_format, "function might "
                               "be possible candidate for %qs format
attribute",
                               format_types[info.format_type].name);
                  }

I'm confident that the above code can be adjusted and moved to the point of the
warning in order to check that the caller of strftime has an attribute format
of type 'strftime' that refers to the same declaration as the nonliteral format
argument in the call to strftime, then avoid warning. I'm not planning to work
on this though.
>From gcc-bugs-return-478761-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Feb 27 15:43:01 2015
Return-Path: <gcc-bugs-return-478761-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 127994 invoked by alias); 27 Feb 2015 15:43:01 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 127044 invoked by uid 48); 27 Feb 2015 15:42:57 -0000
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/65235] [4.8/4.9/5 Regression] Simplifying vec_select of vec_concat miscompiles when first element of vec_concat is const_int
Date: Fri, 27 Feb 2015 16:44:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: rtl-optimization
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: aldyh at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ktkachov at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.5
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-65235-4-Ejkc6oxKFm@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65235-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65235-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-02/txt/msg03093.txt.bz2
Content-length: 230

https://gcc.gnu.org/bugzilla/show_bug.cgi?ide235

--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
--target ??

Could you post a preprocessed source code?

Hmmm... fine line, but maybe this isn't a regression?


  parent reply	other threads:[~2015-02-27 15:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-39438-4@http.gcc.gnu.org/bugzilla/>
2012-01-10 20:39 ` tss at iki dot fi
2014-05-10 16:47 ` hugh at mimosa dot com
2014-05-12 12:26 ` manu at gcc dot gnu.org
2014-05-12 14:58 ` hugh at mimosa dot com
2014-05-12 15:38 ` manu at gcc dot gnu.org
2014-05-12 15:52 ` manu at gcc dot gnu.org
2014-05-12 19:33 ` hugh at mimosa dot com
2015-02-27 16:43 ` manu at gcc dot gnu.org [this message]
2024-06-03  1:48 ` peter0x44 at disroot dot org
2009-03-11 22:57 [Bug c/39438] New: " 4tmuelle at informatik dot uni-hamburg dot de
2009-03-12  9:40 ` [Bug c/39438] " rguenth at gcc dot gnu dot org
2009-03-12  9:58 ` 4tmuelle at informatik dot uni-hamburg dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-39438-4-7LIhwbLljo@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).