[clang] [HLSL] Implement HLSL intialization list support (PR #123141)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 19:11:50 PST 2025


llvm-beanz wrote:

> > How does it not duplicate sub-expressions while also not creating temporary variables to capture results?
> 
> The way I thought of to comprehensively solve this in a clear general way was to:
> 
> * create a new temporary with an anonymous struct type containing the exact sequence of expression types from the initializer
> * initialize that with a flat initializer list containing the original expressions
> * then refer to that temporary in expressions in a new rewritten initializer list matching the target type layout.
> 
> Or perhaps that can be wrapped in a helper function instead.

I think the simpler approach is to wrap any expression that can possibly side-effect in an `OpaqueValueExpr`. That's how we handle side-effecting `inout` arguments. It allows us to emit the expression once during codegen to a temporary that we can then refer to multiple times because the OVE will appear in the AST in multiple initializer list arguments.

https://github.com/llvm/llvm-project/pull/123141


More information about the cfe-commits mailing list