public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning
@ 2024-04-19  9:58 cazfi74 at gmail dot com
  2024-04-19 11:10 ` [Bug c/114780] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: cazfi74 at gmail dot com @ 2024-04-19  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114780
           Summary: Using C23 nullptr as sentinel gives missing sentinel
                    warning
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cazfi74 at gmail dot com
  Target Milestone: ---

Created attachment 57988
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57988&action=edit
Minimum testcase

Compiling attached code with "gcc -std=c2x -Wformat -c nullptrsentinel.c"
produces warning:

nullptrsentinel.c: In function ‘caller’:
nullptrsentinel.c:5:3: warning: missing sentinel in function call [-Wformat=]
    5 |   sentinental(nullptr);

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

* [Bug c/114780] Using C23 nullptr as sentinel gives missing sentinel warning
  2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
@ 2024-04-19 11:10 ` jakub at gcc dot gnu.org
  2024-04-19 22:13 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-19 11:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1
                 CC|                            |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2024-04-19

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57989
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57989&action=edit
gcc14-pr114780.patch

Untested fix.

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

* [Bug c/114780] Using C23 nullptr as sentinel gives missing sentinel warning
  2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
  2024-04-19 11:10 ` [Bug c/114780] " jakub at gcc dot gnu.org
@ 2024-04-19 22:13 ` cvs-commit at gcc dot gnu.org
  2024-04-19 22:25 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-19 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:2afdecccbaf5c5b1c7a235509b37092540906c02

commit r14-10046-g2afdecccbaf5c5b1c7a235509b37092540906c02
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Apr 20 00:12:36 2024 +0200

    c-family: Allow arguments with NULLPTR_TYPE as sentinels [PR114780]

    While in C++ the ellipsis argument conversions include
    "An argument that has type cv std::nullptr_t is converted to type void*"
    in C23 a nullptr_t argument is not promoted in any way, but va_arg
    description says:
    "the type of the next argument is nullptr_t and type is a pointer type that
has the same
    representation and alignment requirements as a pointer to a character
type."
    So, while in C++ check_function_sentinel will never see NULLPTR_TYPE, for
    C23 it can see that and currently we incorrectly warn about those.

    The only question is whether we should warn on any argument with
    nullptr_t type or just about nullptr (nullptr_t argument with integer_zerop
    value).  Through undefined behavior guess one could pass non-NULL pointer
    that way, say by union { void *p; nullptr_t q; } u; u.p = &whatever;
    and pass u.q to ..., but valid code should always pass something that will
    read as (char *) 0 when read using va_arg (ap, char *), so I think it is
    better not to warn rather than warn in those cases.

    Note, clang seems to pass (void *)0 rather than expression of nullptr_t
    type to ellipsis in C23 mode as if it did the C++ ellipsis argument
    conversions, in that case guess not warning about that would be even safer,
    but what GCC does I think follows the spec more closely, even when in a
    valid program one shouldn't be able to observe the difference.

    2024-04-20  Jakub Jelinek  <jakub@redhat.com>

            PR c/114780
            * c-common.cc (check_function_sentinel): Allow as sentinel any
            argument of NULLPTR_TYPE.

            * gcc.dg/format/sentinel-2.c: New test.

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

* [Bug c/114780] Using C23 nullptr as sentinel gives missing sentinel warning
  2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
  2024-04-19 11:10 ` [Bug c/114780] " jakub at gcc dot gnu.org
  2024-04-19 22:13 ` cvs-commit at gcc dot gnu.org
@ 2024-04-19 22:25 ` jakub at gcc dot gnu.org
  2024-04-21  4:09 ` cvs-commit at gcc dot gnu.org
  2024-04-23  6:42 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-19 22:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 14.1 so far.

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

* [Bug c/114780] Using C23 nullptr as sentinel gives missing sentinel warning
  2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-04-19 22:25 ` jakub at gcc dot gnu.org
@ 2024-04-21  4:09 ` cvs-commit at gcc dot gnu.org
  2024-04-23  6:42 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-21  4:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:e802786436851b1f5efca21a14d4f41c83c83f4f

commit r13-8637-ge802786436851b1f5efca21a14d4f41c83c83f4f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Apr 20 00:12:36 2024 +0200

    c-family: Allow arguments with NULLPTR_TYPE as sentinels [PR114780]

    While in C++ the ellipsis argument conversions include
    "An argument that has type cv std::nullptr_t is converted to type void*"
    in C23 a nullptr_t argument is not promoted in any way, but va_arg
    description says:
    "the type of the next argument is nullptr_t and type is a pointer type that
has the same
    representation and alignment requirements as a pointer to a character
type."
    So, while in C++ check_function_sentinel will never see NULLPTR_TYPE, for
    C23 it can see that and currently we incorrectly warn about those.

    The only question is whether we should warn on any argument with
    nullptr_t type or just about nullptr (nullptr_t argument with integer_zerop
    value).  Through undefined behavior guess one could pass non-NULL pointer
    that way, say by union { void *p; nullptr_t q; } u; u.p = &whatever;
    and pass u.q to ..., but valid code should always pass something that will
    read as (char *) 0 when read using va_arg (ap, char *), so I think it is
    better not to warn rather than warn in those cases.

    Note, clang seems to pass (void *)0 rather than expression of nullptr_t
    type to ellipsis in C23 mode as if it did the C++ ellipsis argument
    conversions, in that case guess not warning about that would be even safer,
    but what GCC does I think follows the spec more closely, even when in a
    valid program one shouldn't be able to observe the difference.

    2024-04-20  Jakub Jelinek  <jakub@redhat.com>

            PR c/114780
            * c-common.cc (check_function_sentinel): Allow as sentinel any
            argument of NULLPTR_TYPE.

            * gcc.dg/format/sentinel-2.c: New test.

    (cherry picked from commit 2afdecccbaf5c5b1c7a235509b37092540906c02)

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

* [Bug c/114780] Using C23 nullptr as sentinel gives missing sentinel warning
  2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
                   ` (3 preceding siblings ...)
  2024-04-21  4:09 ` cvs-commit at gcc dot gnu.org
@ 2024-04-23  6:42 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-23  6:42 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 13.3 too.

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

end of thread, other threads:[~2024-04-23  6:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19  9:58 [Bug c/114780] New: Using C23 nullptr as sentinel gives missing sentinel warning cazfi74 at gmail dot com
2024-04-19 11:10 ` [Bug c/114780] " jakub at gcc dot gnu.org
2024-04-19 22:13 ` cvs-commit at gcc dot gnu.org
2024-04-19 22:25 ` jakub at gcc dot gnu.org
2024-04-21  4:09 ` cvs-commit at gcc dot gnu.org
2024-04-23  6:42 ` jakub 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).