diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-07-15 16:39:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 23:39:22 +0000 |
| commit | 21a66267c661a55c8ad27248c0765276dd6f72ea (patch) | |
| tree | 5344d8bfb0829eb6bd336be46f425a718a93cd23 /tests/diagnostics | |
| parent | f48fc786450dd26dab77f8da86aaa622ff75cf6b (diff) | |
Emit additional diagnostic for invalid pointer taking operations (#7663)
* Emit special diagnostic for invalid pointer taking operations
* Update source/slang/slang-diagnostic-defs.h
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
* Add OperatorAddressOf KnownBuiltin modifier
* update error message for non-l-value assignment
* update the diagnostics in the tests
* Use enum based KnownBuiltinDeclName
* format code (#7772)
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
---------
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests/diagnostics')
4 files changed, 28 insertions, 3 deletions
diff --git a/tests/diagnostics/implicit-cast-lvalue.slang.expected b/tests/diagnostics/implicit-cast-lvalue.slang.expected index 10ebfc656..93217b239 100644 --- a/tests/diagnostics/implicit-cast-lvalue.slang.expected +++ b/tests/diagnostics/implicit-cast-lvalue.slang.expected @@ -7,6 +7,7 @@ tests/diagnostics/implicit-cast-lvalue.slang(19): error 30047: argument passed t a(y); ^ tests/diagnostics/implicit-cast-lvalue.slang(19): note 30063: argument was implicitly cast from 'double' to 'float', and Slang does not support using an implicit cast as an l-value with this type +tests/diagnostics/implicit-cast-lvalue.slang(19): note 30049: attempting to assign to a const variable or immutable member; use '[mutating]' attribute on the containing method to allow modification } standard output = { } diff --git a/tests/diagnostics/invalid-constant-pointer-taking.slang b/tests/diagnostics/invalid-constant-pointer-taking.slang new file mode 100644 index 000000000..349f8cc25 --- /dev/null +++ b/tests/diagnostics/invalid-constant-pointer-taking.slang @@ -0,0 +1,23 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv + +RWStructuredBuffer<float> mutable_float_buffer; +RWStructuredBuffer<uint> mutable_uint_buffer; + +StructuredBuffer<float> constant_float_buffer; +StructuredBuffer<uint> constant_uint_buffer; + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain(uint3 threadId : SV_DispatchThreadID) +{ + float* mutablePtr = &mutable_float_buffer[threadId.x]; + + InterlockedAdd(mutable_uint_buffer[threadId.x], 1); + + // Constant pointers arent a thing in slang + // CHECK: error 30078: + float* ptr = &constant_float_buffer[threadId.x]; + + + InterlockedAdd(constant_uint_buffer[0], 1); +}
\ No newline at end of file diff --git a/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected b/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected index fdf04e6b4..d9694276b 100644 --- a/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected +++ b/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected @@ -3,10 +3,11 @@ standard error = { tests/diagnostics/methods/mutating-method-on-rvalue.slang(13): error 30050: mutating method 'increment' cannot be called on an immutable value increment(); ^ -tests/diagnostics/methods/mutating-method-on-rvalue.slang(13): note 30049: a 'this' parameter is an immutable parameter by default in Slang; apply the `[mutating]` attribute to the function declaration to opt in to a mutable `this` +tests/diagnostics/methods/mutating-method-on-rvalue.slang(13): note 30049: attempting to assign to a const variable or immutable member; use '[mutating]' attribute on the containing method to allow modification tests/diagnostics/methods/mutating-method-on-rvalue.slang(25): error 30050: mutating method 'increment' cannot be called on an immutable value gCounter.increment(); ^ +tests/diagnostics/methods/mutating-method-on-rvalue.slang(25): note 30049: attempting to assign to a const variable or immutable member; use '[mutating]' attribute on the containing method to allow modification } standard output = { } diff --git a/tests/diagnostics/setter-method.slang.expected b/tests/diagnostics/setter-method.slang.expected index 1c3dcad48..8df993f78 100644 --- a/tests/diagnostics/setter-method.slang.expected +++ b/tests/diagnostics/setter-method.slang.expected @@ -1,13 +1,13 @@ result code = -1 standard error = { +tests/diagnostics/setter-method.slang(16): note 30049: attempting to assign to a const variable or immutable member; use '[mutating]' attribute on the containing method to allow modification tests/diagnostics/setter-method.slang(16): error 30011: left of '=' is not an l-value. center = value; ^ -tests/diagnostics/setter-method.slang(16): note 30049: a 'this' parameter is an immutable parameter by default in Slang; apply the `[mutating]` attribute to the function declaration to opt in to a mutable `this` +tests/diagnostics/setter-method.slang(21): note 30049: attempting to assign to a const variable or immutable member; use '[mutating]' attribute on the containing method to allow modification tests/diagnostics/setter-method.slang(21): error 30011: left of '=' is not an l-value. this.radius = value; ^ -tests/diagnostics/setter-method.slang(21): note 30049: a 'this' parameter is an immutable parameter by default in Slang; apply the `[mutating]` attribute to the function declaration to opt in to a mutable `this` } standard output = { } |
