Implement -Watomic-implicit-seq-cst
authorJF Bastien <jfbastien@apple.com>
Mon, 10 Sep 2018 20:42:56 +0000 (20:42 +0000)
committerJF Bastien <jfbastien@apple.com>
Mon, 10 Sep 2018 20:42:56 +0000 (20:42 +0000)
commite77b48b07840bbbb3c86cd283b07682637ba3869
tree742239c737d83b2d52f7731bf1464c79c3fc6fcb
parenta5ae613c15a315ea7e575ea94e058cd6524a0aaf
Implement -Watomic-implicit-seq-cst

Summary:
_Atomic and __sync_* operations are implicitly sequentially-consistent. Some
codebases want to force explicit usage of memory order instead. This warning
allows them to know where implicit sequentially-consistent memory order is used.
The warning isn't on by default because _Atomic was purposefully designed to
have seq_cst as the default: the idea was that it's the right thing to use most
of the time. This warning allows developers who disagree to enforce explicit
usage instead.

A follow-up patch will take care of C++'s std::atomic. It'll be different enough
from this patch that I think it should be separate: for C++ the atomic
operations all have a memory order parameter (or two), but it's defaulted. I
believe this warning should trigger when the default is used, but not when
seq_cst is used explicitly (or implicitly as the failure order for cmpxchg).

<rdar://problem/28172966>

Reviewers: rjmccall

Subscribers: dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D51084

llvm-svn: 341860
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/atomic-implicit-seq_cst.c [new file with mode: 0644]
clang/test/Sema/sync-implicit-seq_cst.c [new file with mode: 0644]