public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102965] New: C11 atomic functions accept incompatible arguments
@ 2021-10-27 17:15 msebor at gcc dot gnu.org
  2021-10-27 17:16 ` [Bug c/102965] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-27 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102965
           Summary: C11 atomic functions accept incompatible arguments
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In 7.17.1 Introduction to atomics, the C standard specifies that:

-5-  In the following synopses:
     — An A refers to an atomic type.
     — A C refers to its corresponding non-atomic type.

The synopsis of atomic_compare_exchange listed in 7.17.7.4 The
atomic_compare_exchange generic functions, looks like so:

  _Bool atomic_compare_exchange_strong(volatile A *object, C *expected, C
desired);

I.e., the function is provided for arguments of corresponding types with the
only difference being that the object pointer points to an atomic type.  No
other signatures are provided and so the call to atomic_compare_exchange_strong
in the test case below is invalid and should be diagnosed:

$ cat x.c && gcc -S -Wall -Wextra -Wpedantic x.c
#include <stdatomic.h>

_Atomic long x;
long long y, z;

void f (void)
{
  atomic_compare_exchange_strong (&x, &y, z);   // should be diagnosed
}

Clang issues the obligatory diagnostic as expected:

.c:8:39: warning: incompatible pointer types passing 'long long *' to parameter
      of type 'long *' [-Wincompatible-pointer-types]
  atomic_compare_exchange_strong (&x, &y, z);   // should be diagnosed
                                      ^~
/usr/lib64/clang/7.0.1/include/stdatomic.h:140:112: note: expanded from macro
      'atomic_compare_exchange_strong'
  ...desired) __c11_atomic_compare_exchange_strong(object, expected, desired...
                                                           ^~~~~~~~
1 warning generated.

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

* [Bug c/102965] C11 atomic functions accept incompatible arguments
  2021-10-27 17:15 [Bug c/102965] New: C11 atomic functions accept incompatible arguments msebor at gcc dot gnu.org
@ 2021-10-27 17:16 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-27 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=69404

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The ultimate root cause of the failure to diagnose these incompatibilities is
probably the same as in pr69404.

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

end of thread, other threads:[~2021-10-27 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 17:15 [Bug c/102965] New: C11 atomic functions accept incompatible arguments msebor at gcc dot gnu.org
2021-10-27 17:16 ` [Bug c/102965] " msebor 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).