From 20bd48659d0009de5477380c335e2419f4c66f8b Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Mon, 12 Aug 2024 14:18:02 -0700 Subject: Warn when inout parameter is never written (#4777) Addresses #4698 as one approach to diagnose the potential problem. Emit warnings when a user marks a parameter as `inout` but never writes to it in the function. A new intrinsic function `unmodified(out T)` has been added to explicitly indicate that an `inout` variable will not be modified in the function. This is only one way to address the specific validation error in #4698. In general it seems that DXC does some more extensive checks on actual struct fields (as opposed to observing arbitrary struct writes), so that will be the next step. --- tests/bugs/gl-33-ext.slang | 2 +- tests/bugs/optional.slang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/bugs') diff --git a/tests/bugs/gl-33-ext.slang b/tests/bugs/gl-33-ext.slang index fccde99a3..6df9f286a 100644 --- a/tests/bugs/gl-33-ext.slang +++ b/tests/bugs/gl-33-ext.slang @@ -4,5 +4,5 @@ public struct A { public int state; - [mutating] public int next() { return state; } + public int next() { return state; } }; diff --git a/tests/bugs/optional.slang b/tests/bugs/optional.slang index 3512ba29f..7a220b23d 100644 --- a/tests/bugs/optional.slang +++ b/tests/bugs/optional.slang @@ -14,7 +14,7 @@ struct P } struct Tr { - int test(T t, inout P p) + int test(T t, P p) { const IFoo hit = p.f; let castResult = hit as S; -- cgit v1.2.3