This is an archive of the discontinued LLVM Phabricator instance.

[clang] improve diagnostics for misaligned and large atomics
ClosedPublic

Authored by tschuett on Aug 2 2020, 3:58 PM.

Details

Summary

"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.

Diff Detail

Event Timeline

tschuett created this revision.Aug 2 2020, 3:58 PM
Herald added a project: Restricted Project. · View Herald Transcript
tschuett requested review of this revision.Aug 2 2020, 3:58 PM
xbolva00 added inline comments.
clang/include/clang/Basic/DiagnosticFrontendKinds.td
274

Use ; rather than ( ... ) ?

tschuett updated this revision to Diff 282483.Aug 2 2020, 4:09 PM

Replaced (...) by ;

tschuett edited the summary of this revision. (Show Details)Aug 2 2020, 4:09 PM

Thanks. Can you add some test cases?

tschuett updated this revision to Diff 282485.Aug 2 2020, 4:59 PM

add/updated test

jfb accepted this revision.Aug 3 2020, 8:39 AM
jfb added inline comments.
clang/test/CodeGen/atomics-sema-alignment.c
43 ↗(On Diff #282485)

"the expected (16 bytes)" should be "the expected alignment (16 bytes)"

This revision is now accepted and ready to land.Aug 3 2020, 8:39 AM

I wanted to save space. I know that the alignment is missing there, but the line is already too long.

I have no rights to commit.

tschuett updated this revision to Diff 282637.Aug 3 2020, 8:46 AM

added missing "alignment"

tschuett marked an inline comment as done.Aug 3 2020, 8:47 AM
tschuett marked an inline comment as done.

I would appreciate it, if somebody could commit this patch on my behalf.
Thorsten Schuett
schuett@gmail.com

Thanks.

This revision was automatically updated to reflect the committed changes.