[llvm] [LangRef] Clarify pointer capture spec (PR #194647)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 03:15:31 PDT 2026
================
@@ -3755,72 +3794,6 @@ ultimately only contributes to the return value:
This definition is chosen to allow capture analysis to continue with the return
value in the usual fashion.
-The following describes possible ways to capture a pointer in more detail,
-where unqualified uses of the word "capture" refer to capturing both address
-and provenance.
-
-1. The call stores any bit of the pointer carrying information into a place,
- and the stored bits can be read from the place by the caller after this call
- exits.
-
-.. code-block:: llvm
-
- @glb = global ptr null
- @glb2 = global ptr null
- @glb3 = global ptr null
- @glbi = global i32 0
-
- define ptr @f(ptr %a, ptr %b, ptr %c, ptr %d, ptr %e) {
- store ptr %a, ptr @glb ; %a is captured by this call
-
- store ptr %b, ptr @glb2 ; %b isn't captured because the stored value is overwritten by the store below
- store ptr null, ptr @glb2
-
- store ptr %c, ptr @glb3
- call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured
- store ptr null, ptr @glb3
-
- %i = ptrtoint ptr %d to i64
- %j = trunc i64 %i to i32
- store i32 %j, ptr @glbi ; %d is captured
-
- ret ptr %e ; %e is captured
- }
-
-2. The call stores any bit of the pointer carrying information into a place,
- and the stored bits can be safely read from the place by another thread via
- synchronization.
-
-.. code-block:: llvm
-
- @lock = global i1 true
-
- define void @f(ptr %a) {
- store ptr %a, ptr @glb
- store atomic i1 false, ptr @lock release ; %a is captured because another thread can safely read @glb
- store ptr null, ptr @glb
- ret void
- }
-
-3. The call's behavior depends on any bit of the pointer carrying information
- (address capture only).
-
-.. code-block:: llvm
-
- @glb = global i8 0
-
- define void @f(ptr %a) {
- %c = icmp eq ptr %a, @glb
- br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; captures address of %a only
- BB_EXIT:
- call void @exit()
- unreachable
- BB_CONTINUE:
- ret void
- }
-
-4. The pointer is used as the pointer operand of a volatile access.
----------------
antoniofrighetto wrote:
(To be precise: I do think volatile accesses are a separate concern, unrelated to pointer capture, but would like to be sure we are removing it because of this.)
https://github.com/llvm/llvm-project/pull/194647
More information about the llvm-commits
mailing list