This is an archive of the discontinued LLVM Phabricator instance.

Annotate function parameters with attribute 'noescape'
ClosedPublic

Authored by ahatanak on Sep 21 2017, 9:54 AM.

Details

Reviewers
kubamracek
Summary

I recently tried to commit a patch that adds support for 'noescape' in clang (see https://reviews.llvm.org/D32210) but reverted it because clang failed to build compiler-rt.

The build fails because the block parameters of the following functions defined in the SDKs are preceded with DISPATCH_NOESCAPE, but the declarations in tsan_libdispatch_mac.cc do not have the attribute:

  • dispatch_sync
  • dispatch_barrier_sync
  • dispatch_once
  • dispatch_apply

This patch annotates the declarations in tsan_libdispatch_mac.cc with 'noescape'.

Diff Detail

Event Timeline

ahatanak created this revision.Sep 21 2017, 9:54 AM
kubamracek edited edge metadata.Sep 21 2017, 10:29 AM

What happens when building this code with a compiler that doesn't understand __attribute__((__noescape__))? Is it just ignored?

What happens when building this code with a compiler that doesn't understand __attribute__((__noescape__))? Is it just ignored?

clang will just ignore it and issue a warning ("unknown attribute 'noescape' ignored").

It's possible to guard the declarations with 'noescape' using "__has_attribute(noescape)".

https://clang.llvm.org/docs/LanguageExtensions.html

That's what we should do here. Since the file includes dispatch.h, we should be able to just use the DISPATCH_NOESCAPE macro, which already uses #if __has_attribute.

So is this going to generally break sources which do the same as tsan_libdispatch_mac.cc?

That's what we should do here. Since the file includes dispatch.h, we should be able to just use the DISPATCH_NOESCAPE macro, which already uses #if __has_attribute.

OK, I'll use DISPATCH_NOESCAPE then.

So is this going to generally break sources which do the same as tsan_libdispatch_mac.cc?

Yes, clang will reject it with message "error: conflicting types for ...".

ahatanak updated this revision to Diff 116235.Sep 21 2017, 11:38 AM

Use DISPATCH_NOESCAPE instead of "attribute((noescape))".

kubamracek accepted this revision.Sep 21 2017, 11:49 AM

LGTM with a nit.

lib/tsan/rtl/tsan_libdispatch_mac.cc
181

Please re-align the backslash at the end of the line.

This revision is now accepted and ready to land.Sep 21 2017, 11:49 AM
ahatanak closed this revision.Sep 21 2017, 9:19 PM

Thanks, committed in r313929.