Add internal-use __addressOf instrinsic to replace ⟨
Add internal-use __addressOf instrinsic to replace ⟨aidanfnv wants to merge 2 commits intoshader-slang:masterfrom
__addressOf instrinsic to replace ⟨Conversation
📝 WalkthroughWalkthroughThis pull request introduces a new generic intrinsic operation Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
__addressOf instrinsic__addressOf instrinsic to replace &
There was a problem hiding this comment.
Pull request overview
This PR adds a new __addressOf intrinsic to replace the deprecated & (address-of) operator for internal Slang code and tests. The change maintains identical behavior to the & operator, including the immutable-object safety check (error 30079), while providing a clear internal-use alternative as the public & operator is being deprecated.
Changes:
- Added
__addressOfintrinsic declaration incore.meta.slangwith matching semantics to&operator - Extended immutable-object validation to also check
InternalAddressOfin addition toOperatorAddressOf - Migrated all internal code and test usages from
&to__addressOfacross 13 test files and 1 standard module file
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| source/slang/core.meta.slang | Declares new __addressOf intrinsic with __intrinsic_op(0) and KnownBuiltinDeclName::InternalAddressOf attribute |
| source/slang/slang-ast-support-types.h | Adds InternalAddressOf to KnownBuiltinDeclName enum |
| source/slang/slang-check-expr.cpp | Extends immutable-object check to validate InternalAddressOf alongside OperatorAddressOf |
| tests/spirv/pointer.slang | Migrates &p.data to __addressOf(p.data) |
| tests/llvm/inline-llvm-ir.slang | Migrates &a to __addressOf(a) in memset call |
| tests/language-feature/pointer/coherent-load-store-physical-storage-buffer.slang | Migrates &secondPtrIn[1] to __addressOf(secondPtrIn[1]) |
| tests/language-feature/bitfield/repr.slang | Migrates &s to __addressOf(s) in cast expression |
| tests/language-feature/bitfield/repr-mixed.slang | Migrates &m to __addressOf(m) in cast expression |
| tests/language-feature/bitfield/msvc-repr.slang | Migrates &s to __addressOf(s) in cast expression |
| tests/diagnostics/invalid-constant-pointer-taking.slang | Migrates test to verify error 30079 still fires with __addressOf on constant buffers |
| tests/cpu-program/pointer-deref.slang | Migrates &rec to __addressOf(rec) |
| tests/cpu-program/pointer-basics.slang | Migrates two uses of &value to __addressOf(value) |
| tests/cpu-program/gfx-smoke.slang | Migrates 9 address-of operations to __addressOf in API calls |
| tests/bugs/gh-8659.slang | Migrates &ptr[0] to __addressOf(ptr[0]) |
| tests/bugs/gh-7499.slang | Migrates &arr to __addressOf(arr) in function call |
| tests/bugs/gh-3601.slang | Migrates &p.data to __addressOf(p.data) |
| source/standard-modules/neural/bindless-storage.slang | Migrates &handle[baseIndex + index] to __addressOf(...) in CUDA atomic operation |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/diagnostics/invalid-constant-pointer-taking.slang (1)
9-17:⚠️ Potential issue | 🟡 MinorClarify whether
__addressOfon anRWStructuredBufferelement is intentionally unchecked.The file-level comment (Line 9) reads: "We do not allow taking a pointer from a StructuredBuffer/RWStructuredBuffer."
After the migration:
__getAddress(mutable_float_buffer[...])(Line 17) →error 31160✔__addressOf(mutable_float_buffer[...])(Line 14) → no error CHECKTwo interpretations:
- Intentional escape hatch —
__addressOfdeliberately bypasses the__getAddressguard for mutable buffers, in which case the comment on Line 9 is now stale and should be narrowed to apply only to__getAddress.- Accidental omission — the
error 31160CHECK for the mutable case was dropped during migration, introducing a diagnostic regression.Please either add the missing
// CHECK: ([[#@line+1]]): error ...directive on Line 13, or update the comment on Line 9 to document that__addressOfis permitted onRWStructuredBufferelements.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/diagnostics/invalid-constant-pointer-taking.slang` around lines 9 - 17, The test currently asserts an error for __getAddress but not for __addressOf on elements of mutable_float_buffer; decide whether this is a regression or intended behavior and update the test accordingly: if __addressOf should also be disallowed, add a CHECK directive before the line that declares mutablePtr1 asserting the same diagnostic (error 31160) for __addressOf(mutable_float_buffer[threadId.x]); otherwise, update the file-level comment that currently says "We do not allow taking a pointer from a StructuredBuffer/RWStructuredBuffer." to clarify that the restriction applies only to __getAddress and that __addressOf is permitted, referencing the symbols __addressOf, __getAddress, and mutable_float_buffer in the updated comment so the intent is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/diagnostics/invalid-constant-pointer-taking.slang`:
- Around line 9-17: The test currently asserts an error for __getAddress but not
for __addressOf on elements of mutable_float_buffer; decide whether this is a
regression or intended behavior and update the test accordingly: if __addressOf
should also be disallowed, add a CHECK directive before the line that declares
mutablePtr1 asserting the same diagnostic (error 31160) for
__addressOf(mutable_float_buffer[threadId.x]); otherwise, update the file-level
comment that currently says "We do not allow taking a pointer from a
StructuredBuffer/RWStructuredBuffer." to clarify that the restriction applies
only to __getAddress and that __addressOf is permitted, referencing the symbols
__addressOf, __getAddress, and mutable_float_buffer in the updated comment so
the intent is clear.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (17)
source/slang/core.meta.slangsource/slang/slang-ast-support-types.hsource/slang/slang-check-expr.cppsource/standard-modules/neural/bindless-storage.slangtests/bugs/gh-3601.slangtests/bugs/gh-7499.slangtests/bugs/gh-8659.slangtests/cpu-program/gfx-smoke.slangtests/cpu-program/pointer-basics.slangtests/cpu-program/pointer-deref.slangtests/diagnostics/invalid-constant-pointer-taking.slangtests/language-feature/bitfield/msvc-repr.slangtests/language-feature/bitfield/repr-mixed.slangtests/language-feature/bitfield/repr.slangtests/language-feature/pointer/coherent-load-store-physical-storage-buffer.slangtests/llvm/inline-llvm-ir.slangtests/spirv/pointer.slang
|
Discussed with Yong on Discord that this should not be added and we should instead change |
The prefix
&operator for taking addresses is being deprecated, but internal Slang code and tests need an equivalent mechanism.This change adds
__addressOf, an internal-use intrinsic declared incore.meta.slangwith the same__intrinsic_op(0)behavior as&. It has a newKnownBuiltinDeclName::InternalAddressOfattribute, and the existing immutable-object check inCheckInvokeExprWithCheckedOperandsis extended to also matchInternalAddressOf, so that error 30079 still fires when passing a read-only value, like&. This change also migrates all internal and test usages of&for address-of to__addressOf.