mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 18:36:05 +00:00

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
27 lines
3.6 KiB
C
27 lines
3.6 KiB
C
// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst -Wno-sync-fetch-and-nand-semantics-changed
|
|
|
|
// __sync_* operations are implicitly sequentially-consistent. Some codebases
|
|
// want to force explicit usage of memory order instead.
|
|
|
|
void fetch_and_add(int *ptr, int val) { __sync_fetch_and_add(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void fetch_and_sub(int *ptr, int val) { __sync_fetch_and_sub(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void fetch_and_or(int *ptr, int val) { __sync_fetch_and_or(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void fetch_and_and(int *ptr, int val) { __sync_fetch_and_and(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void fetch_and_xor(int *ptr, int val) { __sync_fetch_and_xor(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void fetch_and_nand(int *ptr, int val) { __sync_fetch_and_nand(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
|
|
void add_and_fetch(int *ptr, int val) { __sync_add_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void sub_and_fetch(int *ptr, int val) { __sync_sub_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void or_and_fetch(int *ptr, int val) { __sync_or_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void and_and_fetch(int *ptr, int val) { __sync_and_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void xor_and_fetch(int *ptr, int val) { __sync_xor_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void nand_and_fetch(int *ptr, int val) { __sync_nand_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
|
|
void bool_compare_and_swap(int *ptr, int oldval, int newval) { __sync_bool_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void val_compare_and_swap(int *ptr, int oldval, int newval) { __sync_val_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
|
|
void synchronize(void) { __sync_synchronize(); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
|
|
void lock_test_and_set(int *ptr, int val) { __sync_lock_test_and_set(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|
|
void lock_release(int *ptr) { __sync_lock_release(ptr); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
|