[PATCH] D102290: [nofree] Only synchronization with release ordering breaks nofree

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 17:20:13 PDT 2021


nhaehnle created this revision.
nhaehnle added reviewers: reames, jdoerfert, nlopes, bollu, uenoku, sstefan1, baziotis.
Herald added subscribers: dexonsmith, okura, kuter, jfb, hiraditya.
nhaehnle requested review of this revision.
Herald added a subscriber: bbn.
Herald added a project: LLVM.

With D101701 <https://reviews.llvm.org/D101701>, a function can no longer be `nofree` if it causes
caller-visible memory to be freed indirectly by another thread. The
checks introduced there are equivalent to the checks for `nosync`.
This change tightens those checks: only an atomic operation with release
(or higher) ordering can break the guarantee made by `nofree`. (Volatile
memory operations are still treated conservatively.)

A correctness argument is as follows. If a memory object is
dereferenceable at point A and freed at point B, then A must
happen-before B (otherwise, there is undefined behavior). If points A
and B are on different threads, then the only way that such a
happens-before relation can be introduced is if there is a release (or
stronger) ordering operation that "happens between" A and B on the
thread that executes A.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102290

Files:
  llvm/include/llvm/IR/Instruction.h
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Transforms/Attributor/nocapture-1.ll
  llvm/test/Transforms/Attributor/nofree.ll
  llvm/test/Transforms/Attributor/nosync.ll
  llvm/test/Transforms/Attributor/undefined_behavior.ll
  llvm/test/Transforms/FunctionAttrs/atomic.ll
  llvm/test/Transforms/FunctionAttrs/nosync.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102290.344604.patch
Type: text/x-patch
Size: 94143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210512/dbd036a9/attachment.bin>


More information about the llvm-commits mailing list