HomePhabricator

[clang] improve diagnostics for misaligned and large atomics

Authored by tschuett on Aug 4 2020, 11:10 AM.

Description

[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

Details

Committed
jfbAug 4 2020, 11:10 AM
Differential Revision
D85102: [clang] improve diagnostics for misaligned and large atomics
Parents
rG31ec6e969d60: [test] Fix another realpath->abspath.
Branches
Unknown
Tags
Unknown