public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruno at clisp dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning
Date: Tue, 05 Sep 2023 00:02:15 +0000	[thread overview]
Message-ID: <bug-111289-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111289
           Summary: Unwarranted -Wanalyzer-va-arg-type-mismatch warning
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 55842
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55842&action=edit
test case foo.c

On the attached program, gcc 13.2.0 with analyzer produces a warning:

$ gcc -fanalyzer -O2 -S foo.c
foo.c: In function ‘do_open’:
foo.c:13:10: warning: ‘va_arg’ expected ‘mode_t’ {aka ‘unsigned int’} but
received ‘int’ for variadic argument 1 of ‘arg’ [CWE-686]
[-Wanalyzer-va-arg-type-mismatch]
   13 |   mode_t mode = va_arg (arg, mode_t);
      |          ^~~~
  ‘main’: events 1-2
    |
    |   20 | main ()
    |      | ^~~~
    |      | |
    |      | (1) entry to ‘main’
    |   21 | {
    |   22 |   do_open ("nonexist.ent/", 0600);
    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |   |
    |      |   (2) calling ‘do_open’ from ‘main’ with 1 variadic argument
    |
    +--> ‘do_open’: events 3-4
           |
           |    8 | do_open (char const *name, ...)
           |      | ^~~~~~~
           |      | |
           |      | (3) entry to ‘do_open’
           |......
           |   13 |   mode_t mode = va_arg (arg, mode_t);
           |      |          ~~~~
           |      |          |
           |      |          (4) ‘va_arg’ expected ‘mode_t’ {aka ‘unsigned
int’} but received ‘int’ for variadic argument 1 of ‘arg’
           |

There is no reason to warn here, because
1) ISO C 99 § 7.15.1.1.(2) says "... the behavior is undefined, except for the
following cases:
— one type is a signed integer type, the other type is the corresponding
unsigned integer type, and the value is representable in both types;
— ..."
Likewise ISO C 23 § 7.16.1.1.(2).
2) The argument that gets passed is an 'int'. The other type, mode_t, is
'unsigned int'. The argument is a constant, and its value 0600 is representable
both as 'int' and as 'unsigned int'.

             reply	other threads:[~2023-09-05  0:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05  0:02 bruno at clisp dot org [this message]
2024-02-15 21:12 ` [Bug analyzer/111289] [13/14 Regression] " dmalcolm at gcc dot gnu.org
2024-02-19 23:10 ` cvs-commit at gcc dot gnu.org
2024-02-19 23:16 ` [Bug analyzer/111289] [13 " dmalcolm at gcc dot gnu.org
2024-02-24  2:58 ` danglin at gcc dot gnu.org
2024-03-24 19:41 ` danglin at gcc dot gnu.org
2024-03-24 20:26 ` bruno at clisp dot org
2024-03-28 18:32 ` cvs-commit at gcc dot gnu.org
2024-04-14  5:22 ` pinskia at gcc dot gnu.org
2024-05-09 17:12 ` cvs-commit at gcc dot gnu.org
2024-05-09 17:50 ` [Bug analyzer/111289] " dmalcolm at gcc dot gnu.org

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-111289-4@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).