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