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
* [Bug analyzer/111289] [13/14 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
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 ` dmalcolm at gcc dot gnu.org
2024-02-19 23:10 ` cvs-commit at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-02-15 21:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Unwarranted |[13/14 Regression]
|-Wanalyzer-va-arg-type-mism |Unwarranted
|atch warning |-Wanalyzer-va-arg-type-mism
| |atch warning
Ever confirmed|0 |1
Last reconfirmed| |2024-02-15
Status|UNCONFIRMED |NEW
--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug report.
Trunk: https://godbolt.org/z/aK9adEYdT
GCC 13.2: https://godbolt.org/z/G1E1o4sbr
The warning was introduced in GCC 13 so can't affect earlier releases
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13/14 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
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
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-19 23:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:
https://gcc.gnu.org/g:5651ad62b08096a155a7e394c7494f5ff1c04f4f
commit r14-9076-g5651ad62b08096a155a7e394c7494f5ff1c04f4f
Author: David Malcolm <dmalcolm@redhat.com>
Date: Mon Feb 19 18:08:05 2024 -0500
analyzer: fix -Wanalyzer-va-arg-type-mismatch false +ve on int types
[PR111289]
gcc/analyzer/ChangeLog:
PR analyzer/111289
* varargs.cc (representable_in_integral_type_p): New.
(va_arg_compatible_types_p): Add "arg_sval" param. Handle integer
types.
(kf_va_arg::impl_call_pre): Pass arg_sval to
va_arg_compatible_types_p.
gcc/testsuite/ChangeLog:
PR analyzer/111289
* c-c++-common/analyzer/stdarg-pr111289-int.c: New test.
* c-c++-common/analyzer/stdarg-pr111289-ptr.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
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 ` dmalcolm at gcc dot gnu.org
2024-02-24 2:58 ` danglin at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-02-19 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[13/14 Regression] |[13 Regression] Unwarranted
|Unwarranted |-Wanalyzer-va-arg-type-mism
|-Wanalyzer-va-arg-type-mism |atch warning
|atch warning |
Status|NEW |ASSIGNED
--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Should be fixed on trunk for gcc 14 by the above patch.
Keeping open to track the backport to gcc 13.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (2 preceding siblings ...)
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
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: danglin at gcc dot gnu.org @ 2024-02-24 2:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
John David Anglin <danglin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |danglin at gcc dot gnu.org
--- Comment #4 from John David Anglin <danglin at gcc dot gnu.org> ---
On hppa64-hp-hpux11.11:
FAIL: c-c++-common/analyzer/stdarg-pr111289-int.c -std=c++98 (test for
warnings, line 60)
FAIL: c-c++-common/analyzer/stdarg-pr111289-int.c -std=c++98 (test for excess
errors)
Excess errors:
/home/dave/gnu/gcc/gcc/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c:5:22:
error: conflicting declaration 'typedef unsigned int mode_t'
/home/dave/gnu/gcc/gcc/gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c:17:30:
warning: 'mode_t' {aka 'short unsigned int'} is promoted to 'int' when passed
through '...'
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (3 preceding siblings ...)
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
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: danglin at gcc dot gnu.org @ 2024-03-24 19:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
--- Comment #5 from John David Anglin <danglin at gcc dot gnu.org> ---
Created attachment 57800
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57800&action=edit
Patch
Don't include <limits.h> on hpux to avoid conflicting type declarations
for mode_t. This fixes test on houx.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (4 preceding siblings ...)
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
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bruno at clisp dot org @ 2024-03-24 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
--- Comment #6 from Bruno Haible <bruno at clisp dot org> ---
(In reply to John David Anglin from comment #5)
> Don't include <limits.h> on hpux to avoid conflicting type declarations
> for mode_t. This fixes test on houx.
Why not entirely remove the '#include <limits.h>'? There is nothing in this
file that needs it.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (5 preceding siblings ...)
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
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-28 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by John David Anglin <danglin@gcc.gnu.org>:
https://gcc.gnu.org/g:86b0b1bec6790f84b7a56fcef2a0a6c8cd91ffef
commit r14-9714-g86b0b1bec6790f84b7a56fcef2a0a6c8cd91ffef
Author: John David Anglin <danglin@gcc.gnu.org>
Date: Thu Mar 28 18:32:12 2024 +0000
Fix failure of c-c++-common/analyzer/stdarg-pr111289-int.c on hpux
2024-03-28 John David Anglin <danglin@gcc.gnu.org>
gcc/testsuite/ChangeLog:
PR analyzer/111289
* c-c++-common/analyzer/stdarg-pr111289-int.c: Don't include
<limits.h>.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (6 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-14 5:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] [13 Regression] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (7 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-09 17:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by David Malcolm
<dmalcolm@gcc.gnu.org>:
https://gcc.gnu.org/g:67d104f3a032ee64bae335269bf1b8434785cc63
commit r13-8755-g67d104f3a032ee64bae335269bf1b8434785cc63
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu May 9 13:09:31 2024 -0400
analyzer: fix -Wanalyzer-va-arg-type-mismatch false +ve on int types
[PR111289]
Backported from commit r14-9076-g5651ad62b08096 (moving new tests from
c-c++-common to gcc.dg).
gcc/analyzer/ChangeLog:
PR analyzer/111289
* varargs.cc (representable_in_integral_type_p): New.
(va_arg_compatible_types_p): Add "arg_sval" param. Handle integer
types.
(kf_va_arg::impl_call_pre): Pass arg_sval to
va_arg_compatible_types_p.
gcc/testsuite/ChangeLog:
PR analyzer/111289
* gcc.dg/analyzer/stdarg-pr111289-int.c: New test.
* gcc.dg/analyzer/stdarg-pr111289-ptr.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug analyzer/111289] Unwarranted -Wanalyzer-va-arg-type-mismatch warning
2023-09-05 0:02 [Bug analyzer/111289] New: Unwarranted -Wanalyzer-va-arg-type-mismatch warning bruno at clisp dot org
` (8 preceding siblings ...)
2024-05-09 17:12 ` cvs-commit at gcc dot gnu.org
@ 2024-05-09 17:50 ` dmalcolm at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-05-09 17:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111289
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[13 Regression] Unwarranted |Unwarranted
|-Wanalyzer-va-arg-type-mism |-Wanalyzer-va-arg-type-mism
|atch warning |atch warning
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Should be fixed for GCC 13 (for the upcoming GCC 13.3) by the above patch.
^ 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).