public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60296] New: Confusing -Wformat warning on invalid format string
@ 2014-02-20 22:53 chengniansun at gmail dot com
  2014-02-21  8:22 ` [Bug c/60296] " schwab@linux-m68k.org
  2015-02-27 15:35 ` manu at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: chengniansun at gmail dot com @ 2014-02-20 22:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60296

            Bug ID: 60296
           Summary: Confusing -Wformat warning on invalid format string
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

Gcc emits two warnings on "printf("%.%*d\n", 9)", of which the format string is
invalid. IMHO, the two warning messages are contradictory somehow. The first
message says a conversion type is missing in the format string(if I understand
it correctly), but the second says that we need to add a data argument to
printf to match a "%d"? 

One more question, in the second message, does "‘%d’" refer to "%*d" in the
format string, or just a hard-coded string in the gcc code? 

Lastly, the compiled executable just treats the format string as a string
"%*d". Is this the way how gcc treats this invalid string? If yes, it might be
better to warn on it in the same way, that is, extra data argument not used by
the format string.  




$: cat s.c 
#include <stdio.h>
int main() {
  printf("%.%*d\n", 9);
  return 0;
}
$: gcc-trunk -Wformat=2 s.c 
s.c: In function ‘main’:
s.c:3:3: warning: conversion lacks type at end of format [-Wformat=]
   printf("%.%*d\n", 9);
   ^
s.c:3:3: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
$: ./a.out 
%*d
$: clang-trunk -Wformat=2 s.c 
s.c:3:21: warning: data argument not used by format string
[-Wformat-extra-args]
  printf("%.%*d\n", 9);
         ~~~~~~~~~  ^
1 warning generated.
>From gcc-bugs-return-444411-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Feb 20 23:27:17 2014
Return-Path: <gcc-bugs-return-444411-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 32551 invoked by alias); 20 Feb 2014 23:27:17 -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 32532 invoked by uid 55); 20 Feb 2014 23:27:12 -0000
From: "hubicka at ucw dot cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/60295] [4.9 Regression] Too many lto1-wpa-stream processes are forked
Date: Thu, 20 Feb 2014 23:27:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: lto
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hubicka at ucw dot cz
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-60295-4-WujXfWmzR7@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60295-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60295-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: 2014-02/txt/msg02168.txt.bz2
Content-length: 1542

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`295

--- Comment #1 from Jan Hubicka <hubicka at ucw dot cz> ---
> It happens during a GCC LTO+FDO bootstrap with
>
> ../src-trunk/configure \
>      --prefix=/usr/4.9.0 --enable-clocale=gnu --with-system-zlib
> --enable-shared --with-demangler-in-ld --with-build-config=bootstrap-lto
> --disable-werro
> r --with-fpmath=sse --enable-languages=c,c++,fortran,java,lto,objc
>
> make -j 8 -C bld profiledbootstrap
>
> There are more than 120 lto1-wpa-stream processes forked due to r207515.
> Are they really necessary?

This does not happen for me.

What -flto parameter you use?  If you pass -flto or -flto=jobserv, you won't
get multiple WPA forks from one LTO compilation. If you pass -flto\x16 as I
do, you will get 16 processes, if you manage to build 16 binaries at once,
you will get 16^2.
But just minute later you would get 16^2 ltrans processes, too, so I do not
see this introducing a new bottleneck.  I did some measurements of forked
WPA memory use and it was always bellow ltrans use.

Since bootstrap-lto passes only -flto, it also may be just some bug in parsing
the parameters?
stream_out (char *temp_filename, lto_symtab_encoder_t encoder, bool last)
{
#ifdef HAVE_WORKING_FORK
  static int nruns;

  if (!lto_parallelism || lto_parallelism == 1)
    {
      do_stream_out (temp_filename, encoder);
      return;
    }
  ... eventually do the fork.

What is lto_paralellism for you?

Honza
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/60296] Confusing -Wformat warning on invalid format string
  2014-02-20 22:53 [Bug c/60296] New: Confusing -Wformat warning on invalid format string chengniansun at gmail dot com
@ 2014-02-21  8:22 ` schwab@linux-m68k.org
  2015-02-27 15:35 ` manu at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2014-02-21  8:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60296

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
For the % conversion there are no modifiers defined, so gcc stops before the
second %, parsing the rest as %*d, which requires two arguments.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/60296] Confusing -Wformat warning on invalid format string
  2014-02-20 22:53 [Bug c/60296] New: Confusing -Wformat warning on invalid format string chengniansun at gmail dot com
  2014-02-21  8:22 ` [Bug c/60296] " schwab@linux-m68k.org
@ 2015-02-27 15:35 ` manu at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu.org @ 2015-02-27 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |manu at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
To be honest, I find the messages by gcc far clearer (except for missing
precise locations). In particular, if we think about suggesting a fix, gcc
could suggest to replace %. with %.d to match '9' and then the second warning
will still be valid (since there are no arguments to match %*d). Currently, gcc
tries to match 9 to %. and skips both on error, that is why it complains about
a missing argument for %d. GCC could not skip the argument '9' and try to match
%*d with 9. I can imagine cases where one strategy is clearer than the other
and viceversa. However, the clang warning does not actually say what is wrong
at all. It does not seem very helpful.

About your questions, yes %d refers to %*d in the format string, and the %d
printed by the warning is not read from the string but hard-coded in the gcc
sources.

What printf does when given invalid arguments is not up to GCC but the C
library that implements printf.

I will close this as invalid then. Improving the location info is what will
make these cases far clearer (PR52952). Then, we can print:

warning: conversion lacks type at end of format [-Wformat=]
   printf("%.%*d\n", 9);
           ~^
note: use '%.d' to match argument of type 'int'
   printf("%.%*d\n", 9);
           ~^        ^
           %.d

warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
   printf("%.%*d\n", 9);
               ^
>From gcc-bugs-return-478751-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Feb 27 15:15:21 2015
Return-Path: <gcc-bugs-return-478751-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 34133 invoked by alias); 27 Feb 2015 15:15:21 -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 34071 invoked by uid 48); 27 Feb 2015 15:15:17 -0000
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/65238] [5 Regression] __has_attribute is not handled properly with -traditional-cpp.
Date: Fri, 27 Feb 2015 15:36:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: preprocessor
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mpolacek at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc component target_milestone everconfirmed
Message-ID: <bug-65238-4-DNwvyFkjLc@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65238-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65238-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/msg03083.txt.bz2
Content-length: 686

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-27
                 CC|                            |mpolacek at gcc dot gnu.org
          Component|c                           |preprocessor
   Target Milestone|---                         |5.0
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r217292.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-27 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-20 22:53 [Bug c/60296] New: Confusing -Wformat warning on invalid format string chengniansun at gmail dot com
2014-02-21  8:22 ` [Bug c/60296] " schwab@linux-m68k.org
2015-02-27 15:35 ` manu at gcc dot gnu.org

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).