From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DFC063858D35; Tue, 5 Sep 2023 00:02:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFC063858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693872135; bh=q5ubmTmWI9S6vFyayvXEqT7hW/tTt0HGDyp5TCmnnDQ=; h=From:To:Subject:Date:From; b=nL6sR5MYlQiX3QoZIBnD0wCVuoGLbERpZbV/AFLYrGS3C2TfpOeA6bu/o4pV3qsqe GpzLpQZE1h40ySFPnFAs19LBXfqHIK67yX0S3JROStBIvfpdbnGfybDEOkL369DBKb bjeEEN3Eyy1LAIwDqiNHOOX3lYPV31I4Tavu1Cuk= From: "bruno at clisp dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111289 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=3D55842&action=3Dedit 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 =E2=80=98do_open=E2=80=99: foo.c:13:10: warning: =E2=80=98va_arg=E2=80=99 expected =E2=80=98mode_t=E2= =80=99 {aka =E2=80=98unsigned int=E2=80=99} but received =E2=80=98int=E2=80=99 for variadic argument 1 of =E2=80=98arg=E2= =80=99 [CWE-686] [-Wanalyzer-va-arg-type-mismatch] 13 | mode_t mode =3D va_arg (arg, mode_t); | ^~~~ =E2=80=98main=E2=80=99: events 1-2 | | 20 | main () | | ^~~~ | | | | | (1) entry to =E2=80=98main=E2=80=99 | 21 | { | 22 | do_open ("nonexist.ent/", 0600); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) calling =E2=80=98do_open=E2=80=99 from =E2=80=98main=E2= =80=99 with 1 variadic argument | +--> =E2=80=98do_open=E2=80=99: events 3-4 | | 8 | do_open (char const *name, ...) | | ^~~~~~~ | | | | | (3) entry to =E2=80=98do_open=E2=80=99 |...... | 13 | mode_t mode =3D va_arg (arg, mode_t); | | ~~~~ | | | | | (4) =E2=80=98va_arg=E2=80=99 expected =E2=80= =98mode_t=E2=80=99 {aka =E2=80=98unsigned int=E2=80=99} but received =E2=80=98int=E2=80=99 for variadic argument 1 of= =E2=80=98arg=E2=80=99 | There is no reason to warn here, because 1) ISO C 99 =C2=A7 7.15.1.1.(2) says "... the behavior is undefined, except= for the following cases: =E2=80=94 one type is a signed integer type, the other type is the correspo= nding unsigned integer type, and the value is representable in both types; =E2=80=94 ..." Likewise ISO C 23 =C2=A7 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 represent= able both as 'int' and as 'unsigned int'.=