[PATCH] D51084: Implement -Watomic-implicit-seq-cst

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 28 17:02:22 PDT 2018


jfb added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:10668
+  if (Source->isAtomicType() || Target->isAtomicType())
+    S.Diag(E->getBeginLoc(), diag::warn_atomic_implicit_seq_cst);
+
----------------
rjmccall wrote:
> Why would the target be an atomic type?  And if it is an atomic type, isn't that an initialization of a temporary?  In what situation does it make sense to order the initialization of a temporary?
In this case:

```
void bad_assign_1(int i) {
  atom = i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
}
```

We want to warn on assignment to atomics being implicitly `seq_cst`.

Though you're right, initialization shouldn't warn because it isn't atomic. The issue is that `ATOMIC_VAR_INIT` is what needs to get used, and that's weird to test. I'll add a test that just assigns (which is what `ATOMIC_VAR_INIT` expands to for clang), and I'll need to update the code to detect that pattern and avoid warning in that case. I guess I have to look at the `Expr` and figure out if the LHS is a `Decl` or something like that.


Repository:
  rC Clang

https://reviews.llvm.org/D51084





More information about the cfe-commits mailing list