summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/void-function-returning-value.slang.expected
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-06-15 12:05:04 -0700
committerGitHub <noreply@github.com>2020-06-15 12:05:04 -0700
commitd84cfb766b089c03f9545588a8590efea1749770 (patch)
tree3bc00b9a85e52709f682f1559a3b354a5bc77735 /tests/diagnostics/void-function-returning-value.slang.expected
parent90444f8366255f274993ce4699738d9ab7cf4ee1 (diff)
Remove implicit conversions to `void` (#1388)
* Remove implicit conversions to `void` Fixes #1372 The standard library code had accidentally introduced implicit-conversion `__init` operations on the `void` type that accepted each of the other basic types, so that a function written like: ```hlsl void bad() { return 1; } ``` would translate to: ```hlsl void bad() { return (void)1; } ``` The dual problesm are that the input code should have produced a diagnostic of some kind, and the output code doesn't appear to compile correctly through fxc. This change introduces several fixes aimed at this issue: * First, the problem in the stdlib code is plugged: we don't introduce implicit conversion operations *to* or *from* `void` (we'd only been banning it in one direction before) * Next, an explicit `__init` was added to `void` that accepts *any* type so that existing HLSL code that might do `(void) someExpression` to ignore a result will continue to work. This is a compatibility feature, and it might be argued that we should at least warn when it is used. Note that this function is expected to never appear in output HLSL/GLSL because its result will never be used, and it is marked `[__readNone]` allowing calls to it to be eliminated as dead code. * During IR lowering, we now take care to only emit the `IRReturnVal` instruction type if there is a non-`void` value being returned, and use `IRReturnVoid` for both the case where no expression was used in the `return` statement *and* the case where an expression of type `void` is returned. * A test case was added to confirm that returning `1` from a `void` function isn't allowed, while returning `(void) 1` *is*. The net result of these changes is that we now produce an error for the bad input code, we allow explicit casts to `void` as a compatibility feature, and we are more robust about treating `void` as if it is an ordinary type in the front-end. * fixup: missing file
Diffstat (limited to 'tests/diagnostics/void-function-returning-value.slang.expected')
-rw-r--r--tests/diagnostics/void-function-returning-value.slang.expected7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/diagnostics/void-function-returning-value.slang.expected b/tests/diagnostics/void-function-returning-value.slang.expected
new file mode 100644
index 000000000..a94132971
--- /dev/null
+++ b/tests/diagnostics/void-function-returning-value.slang.expected
@@ -0,0 +1,7 @@
+result code = -1
+standard error = {
+tests/diagnostics/void-function-returning-value.slang(16): error 30019: expected an expression of type 'void', got 'int'
+tests/diagnostics/void-function-returning-value.slang(16): note: explicit conversion from 'int' to 'void' is possible
+}
+standard output = {
+}