Files
clang-p2996/clang/test/SemaHLSL/Language/OutputParameters.hlsl
Chris B 89fb8490a9 [HLSL] Implement output parameter (#101083)
HLSL output parameters are denoted with the `inout` and `out` keywords
in the function declaration. When an argument to an output parameter is
constructed a temporary value is constructed for the argument.

For `inout` pamameters the argument is initialized via copy-initialization
from the argument lvalue expression to the parameter type. For `out`
parameters the argument is not initialized before the call.

In both cases on return of the function the temporary value is written
back to the argument lvalue expression through an implicit assignment
binary operator with casting as required.

This change introduces a new HLSLOutArgExpr ast node which represents
the output argument behavior. The OutArgExpr has three defined children:
- An OpaqueValueExpr of the argument lvalue expression.
- An OpaqueValueExpr of the copy-initialized parameter.
- A BinaryOpExpr assigning the first with the value of the second.

Fixes #87526

---------

Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
Co-authored-by: John McCall <rjmccall@gmail.com>
2024-08-31 10:59:08 -05:00

35 lines
1.7 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify -Wdouble-promotion -Wconversion %s
void OutVecFn(out float3) {}
void InOutVecFn(inout float3) {}
// Case 1: Calling out and inout parameters with types that cannot be
// back-converted. In HLSL 2021 and earlier this only occurs when passing scalar
// arguments to vector parameters because scalar->vector conversion is implicit,
// but vector->scalar is not.
void case1() {
float f;
int i;
OutVecFn(f); // expected-error{{illegal scalar extension cast on argument f to out paramemter}}
InOutVecFn(f); // expected-error{{illegal scalar extension cast on argument f to inout paramemter}}
OutVecFn(i); // expected-error{{illegal scalar extension cast on argument i to out paramemter}}
InOutVecFn(i); // expected-error{{illegal scalar extension cast on argument i to inout paramemter}}
}
// Case 2: Conversion warnings on argument initialization. Clang generates
// implicit conversion warnings only on the writeback conversion for `out`
// parameters since the parameter is not initialized from the argument. Clang
// generates implicit conversion warnings on both the parameter initialization
// and the writeback for `inout` parameters since the parameter is both copied
// in and out of the function.
void OutFloat(out float) {}
void InOutFloat(inout float) {}
void case2() {
double f;
OutFloat(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
InOutFloat(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} expected-warning{{implicit conversion loses floating-point precision: 'double' to 'float'}}
}