On Wed Jun 28 11:20:13 2023 +0000, Giovanni Mascellani wrote:
I'm not convinced ownership for `semantic->name` is handled correctly. Here `hlsl_new_var()` acquires ownership of the name, but at the same time it seems that the `struct parse_variable_def` still retains it (given that `free_parse_variable_def()` is called in `initialize_vars()`). Am I missing something?
You are right, I didn't realize because there is no test that triggers an invalid read, we don't test semantics in variable|struct declarations, which makes sense since they don't show up in the output bytecode unlike when they appear in function parameters, function return value, or struct fields.
This test is enough to trigger the failure: ``` float a : SEM;
float4 main() : sv_target { return float4(a, a, a, 0); } ```
I think that the proper solution would be making the new variable store a copy of `var->semantic.name`, just as it stores a copy of `var->name`. I am even thinking that hlsl_new_variable() should take care of creating a copy of both strings internally.