Thorsten Schuett
e18c6ef6b4
[clang] improve diagnostics for misaligned and large atomics
...
"Listing the alignment and access size (== expected alignment) in the warning
seems like a good idea."
solves PR 46947
struct Foo {
struct Bar {
void * a;
void * b;
};
Bar bar;
};
struct ThirtyTwo {
struct Large {
void * a;
void * b;
void * c;
void * d;
};
Large bar;
};
void braz(Foo *foo, ThirtyTwo *braz) {
Foo::Bar bar;
__atomic_load(&foo->bar, &bar, __ATOMIC_RELAXED);
ThirtyTwo::Large foobar;
__atomic_load(&braz->bar, &foobar, __ATOMIC_RELAXED);
}
repro.cpp:21:3: warning: misaligned atomic operation may incur significant performance penalty; the expected (16 bytes) exceeds the actual alignment (8 bytes) [-Watomic-alignment]
__atomic_load(&foo->bar, &bar, __ATOMIC_RELAXED);
^
repro.cpp:24:3: warning: misaligned atomic operation may incur significant performance penalty; the expected (32 bytes) exceeds the actual alignment (8 bytes) [-Watomic-alignment]
__atomic_load(&braz->bar, &foobar, __ATOMIC_RELAXED);
^
repro.cpp:24:3: warning: large atomic operation may incur significant performance penalty; the access size (32 bytes) exceeds the max lock-free size (16 bytes) [-Watomic-alignment]
3 warnings generated.
Differential Revision: https://reviews.llvm.org/D85102
2020-08-04 11:10:29 -07:00
Tim Northover
9dc1d0c74e
[Atomics] warn about atomic accesses using libcalls
...
If an atomic variable is misaligned (and that suspicion is why Clang emits
libcalls at all) the runtime support library will have to use a lock to safely
access it, with potentially very bad performance consequences. There's a very
good chance this is unintentional so it makes sense to issue a warning.
Also give it a named group so people can promote it to an error, or disable it
if they really don't care.
llvm-svn: 330566
2018-04-23 08:16:24 +00:00