This is an archive of the discontinued LLVM Phabricator instance.

Disallow pointers to const in __sync_fetch_and_xxx
ClosedPublic

Authored by aaron.ballman on Apr 23 2018, 4:19 AM.

Details

Summary

The following code is currently accepted without a diagnostic when it should be prohibited:

void f(const int *ptr) {
  __sync_fetch_and_add(ptr, 1);
}

NB: the above code is diagnosed by GCC and ICC. However, Clang attempts to modify the underlying object, which seems dangerous.

Diff Detail

Event Timeline

aaron.ballman created this revision.Apr 23 2018, 4:19 AM

Please always upload all patches with full context (-U99999)

Updated with more context.

Please always upload all patches with full context (-U99999)

I'm not keen on uploading patches with that much context. For instance, it disables syntax highlighting in Phab for many of our files. However, perhaps 100 lines of context was a bit optimistic.

Adding a few more potential reviewers.

LGTM, although you might consider testing a broader set of builtins. Maybe at least one from the __atomic_* family?

aaron.ballman accepted this revision.May 5 2018, 10:43 AM

Committed in r331598, with an additional test case.

(Accepting officially on behalf of @rjmccall so that I can close the review.)

This revision is now accepted and ready to land.May 5 2018, 10:43 AM
aaron.ballman closed this revision.May 5 2018, 10:43 AM