]> git.ipfire.org Git - thirdparty/gcc.git/commit
c-family: check qualifiers of arguments to __atomic built-ins (PR 95378)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 17 Jun 2020 18:48:05 +0000 (19:48 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 17 Jun 2020 19:02:53 +0000 (20:02 +0100)
commitd2384b7b24f8557b66f6958a05ea99ff4307e75c
tree87421899129a396ec7cdf476312dc30ae7cd7f22
parent4e49b994de060d4a6c9318d0ed52ef038153426e
c-family: check qualifiers of arguments to __atomic built-ins (PR 95378)

Currently the __atomic_{load,store,exchange,compare_exchange} built-ins
will happily store values through pointers to const, or use pointers to
volatile as the input and output arguments. This patch ensures that any
pointer that will be written through does not point to a const object,
and only the pointer to the atomic variable can be volatile.

This differs slightly from Clang, which allows the third argument to
__atomic_exchange (the one that is used to return the old value) to be
volatile if and only if the first argument is volatile. That doesn't
seem useful.

For C++ emit errors, but for C use pedwarns that are controlled by
-Wincompatible-pointer-types.

gcc/c-family/ChangeLog:

* c-common.c (get_atomic_generic_size): Check cv-qualifiers in
pointer arguments.

gcc/testsuite/ChangeLog:

* c-c++-common/pr95378.c: New test.
gcc/c-family/c-common.c
gcc/testsuite/c-c++-common/pr95378.c [new file with mode: 0644]