diff options
| author | venkataram-nv <vedavamadath@nvidia.com> | 2024-08-16 15:18:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-16 15:18:17 -0700 |
| commit | b411c05bc074f53037e32b23583b85adcfbf81fc (patch) | |
| tree | 412144254f0767675d89ae5b3626b7057c4052b5 | |
| parent | 9bf5dc93d5d46f64b0da298e03ba3233539af6ef (diff) | |
Include inout cast operation as an aliasing instruction (#4859)
Previously, the warnings were:
```
environment.slang(22): warning 41022: inout parameter 'seed' is never written to
public float3 environment_sample(StructuredBuffer <Environment_sample_data> sample_buffer, inout int seed)
^~~~~~~~~~~~~~~~~~
hit.slang(5): warning 41022: inout parameter 'seed' is never written to
float3 sample_lights(inout uint seed)
^~~~~~~~~~~~~
```
With this commit they should not be emitted.
| -rw-r--r-- | source/slang/slang-ir-use-uninitialized-values.cpp | 1 | ||||
| -rw-r--r-- | tests/diagnostics/inout-never-written.slang | 28 |
2 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang-ir-use-uninitialized-values.cpp b/source/slang/slang-ir-use-uninitialized-values.cpp index b8dfcc33c..8b940d30d 100644 --- a/source/slang/slang-ir-use-uninitialized-values.cpp +++ b/source/slang/slang-ir-use-uninitialized-values.cpp @@ -110,6 +110,7 @@ namespace Slang case kIROp_FieldAddress: case kIROp_GetElement: case kIROp_GetElementPtr: + case kIROp_InOutImplicitCast: return true; default: break; diff --git a/tests/diagnostics/inout-never-written.slang b/tests/diagnostics/inout-never-written.slang index 0bc59ecf3..f4d4bce7e 100644 --- a/tests/diagnostics/inout-never-written.slang +++ b/tests/diagnostics/inout-never-written.slang @@ -44,5 +44,31 @@ struct B [mutating] int next() { return state; } }; +// Sometimes an inOutImplicitCast is done, +// this needs to be tracked as an alias; +// none of the following functions should +// generate warnings +uint lcg(inout uint prev) +{ + const uint LCG_A = 1664525u; + const uint LCG_C = 1013904223u; + prev = (LCG_A * prev + LCG_C); + return prev & 0x00FFFFFF; +} + +float rnd(inout uint prev) +{ + return ((float) lcg(prev) / (float) 0x01000000); +} + +float3 sample(inout int seed) +{ + float3 xi; + xi.x = rnd(seed); + xi.y = rnd(seed); + xi.z = rnd(seed); + return xi.z; +} + //CHK-NOT: warning 41022 -//CHK-NOT: warning 41023
\ No newline at end of file +//CHK-NOT: warning 41023 |
