public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning
@ 2023-09-05  0:02 bruno at clisp dot org
  2024-02-15 21:12 ` [Bug analyzer/111289] [13/14 Regression] " dmalcolm at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bruno at clisp dot org @ 2023-09-05  0:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2024-05-09 17:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05  0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
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

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