Bug 151756 - gcc miscounts arguments in format-string warnings
Summary: gcc miscounts arguments in format-string warnings
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc   
(Show other bugs)
Version: rawhide
Hardware: s390x
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2005-03-22 01:14 UTC by Tom Lane
Modified: 2013-07-03 03:04 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-03-22 06:18:57 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Tom Lane 2005-03-22 01:14:20 UTC
Description of problem:
gcc produces an incorrect warning message

$ gcc -v
Using built-in specs.
Target: s390x-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++,objc,java,f95
--enable-java-awt=gtk --host=s390x-redhat-linux
Thread model: posix
gcc version 4.0.0 20050320 (Red Hat 4.0.0-0.35)

$ cat atest.c
#include <stdio.h>

int main()
  long long     len = 1;

  fprintf(stderr, "len = %d\n", len);

  return 0;

$ gcc -Wall atest.c
atest.c: In function 'main':
atest.c:7: warning: format '%d' expects type 'int', but argument 3 has type
'long long int'

-- that's the expected result, but watch this:

$ gcc -Wall -Wp,-D_FORTIFY_SOURCE=2  -O atest.c
atest.c: In function 'main':
atest.c:7: warning: format '%d' expects type 'int', but argument 4 has type
'long long int'

Why is the argument number now off by one?

Version-Release number of selected component (if applicable):

How reproducible:
100% on this arch, have not tried others

Steps to Reproduce:
Actual results:

Expected results:

Additional info:
In itself this is not much more than cosmetic, but I wonder if it is a symptom
of a bug that could have more serious consequences.

Comment 1 Jakub Jelinek 2005-03-22 06:18:57 UTC
This is a consequence of __fprintf_chk being actually called rather than
fprintf.  And __fprintf_chk has one additional argument, before the format
string.  As *printf are stdarg functions, the extra argument simply must go
before the ... arguments.

Comment 2 Tom Lane 2005-03-22 07:18:39 UTC
I don't think I believe that explanation, because  the bogus message depends on whether -O is present.

Comment 3 Jakub Jelinek 2005-03-22 10:20:57 UTC
Of course it depends on -O*, because -D_FORTIFY_SOURCE={1,2} is only in affect
with -O1 and higher.  The way it is implemented, it can't work for non-optimized

Note You need to log in before you can comment on or make changes to this bug.