Commit 4724809
authored
Ensure generated getters of optional operands don't crash (#10019)
Some IR instructions have optional operands. The getters generated by
Fiddle for those instructions did not consider the optionality, and
attempt to fetch them regardless, triggering an assertion if called.
This PR makes the generated getters behave like most of the hand-written
getters with optional operands, by checking that the operand exists
first. If it doesn't, `nullptr` is returned, which the caller is
expected to handle. I don't think this can break existing code, as the
previous behavior when fetching a non-existent optional operand was to
simply crash.
This is in preparation for a PR to implement
shader-slang/spec#39, but is a separate issue,
which is why I'm submitting this change in a separate PR. It's of
particular importance there, as a new optional data layout operand is
added, which is often queried with the Fiddle-generated getter in
`IRPtrType`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Changes to the Slang Shader Compiler
This PR fixes a crash in the IR (Intermediate Representation) layer by
making Fiddle-generated instruction accessor getters handle optional
operands safely.
### Compiler Stages Affected
- IR Stage (Primary): Changes are in the IR code generation and
generated IR accessor implementations:
- source/slang/slang-ir.h.lua — Fiddle code-generator: now propagates an
`optional` flag into per-operand metadata and adjusts generation logic
(including handling single-operand forms and simplifying the expression
used when emitting getters).
- source/slang/slang-ir-insts.h — generated IR instruction accessor
getters: getter bodies now check whether an optional operand is present
(index < operand count) and return nullptr when missing instead of
asserting/crashing.
No changes to lexer, parser, semantic analysis, or code generation
stages.
### Backend Impact
- No backend-specific source files were modified, but the IR accessors
are used by all backends. This makes queries for optional operands safe
across targets that inspect IR (SPIRV, HLSL, GLSL, Metal, CUDA, WGSL,
etc.). The change prevents assertion failures when backends or other
passes query absent optional operands and is preparatory for adding a
frequently-queried optional data layout operand in a follow-up PR.
### Public API Impact
- No public API headers were modified (include/slang.h,
slang-com-helper.h were not changed). Function signatures of the
generated getters were not changed; only their bodies/behavior were
adjusted.
### Commits / Notable Implementation Details
- Commit message: "Fix single-operand insts + more compact expression" —
addresses single-operand instruction handling and simplifies the emitted
getter expression.
- The generator now marks operands with optional = true when appropriate
and emits getter bodies that check operand existence (returning nullptr
when missing), matching typical hand-written getters.
### Summary
Fiddle's IR getter generation now respects optional operands, avoiding
crashes when code queries absent optional operands and aligning
generated getters with established hand-written behavior. This is a
non-breaking internal change to IR accessor implementations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 2942719 commit 4724809
2 files changed
+12
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2960 | 2960 | | |
2961 | 2961 | | |
2962 | 2962 | | |
2963 | | - | |
2964 | | - | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
2965 | 2969 | | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
2966 | 2973 | | |
| 2974 | + | |
2967 | 2975 | | |
2968 | 2976 | | |
2969 | 2977 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| |||
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
| 194 | + | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
| |||
0 commit comments