================ @@ -802,16 +869,14 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr( ArraySubsExpr->getType()->isHLSLResourceRecordArray() && "expected resource array subscript expression"); - // let clang codegen handle local resource array subscripts - const VarDecl *ArrayDecl = dyn_cast<VarDecl>(getArrayDecl(ArraySubsExpr)); + // Let clang codegen handle local resource array subscripts, + // or when the subscript references on opaque expression (as part of + // ArrayInitLoopExpr AST node). + const VarDecl *ArrayDecl = + dyn_cast_or_null<VarDecl>(getArrayDecl(ArraySubsExpr)); ---------------- hekota wrote:
It may happen when the `ArraySubscriptExpr` refers to an `OpaqueValueExpr` as part of an `ArrayInitLoopExpr ` AST construct. See https://godbolt.org/z/MzKsf8Kh5. The `ArrayInitLoopExpr` AST node is used for array initialization from another array. Notice how the first and the third `ArraySubscriptExpr` are the same (same pointer value)? We only do HLSL codegen on the first `ArraySubscriptExpr` where we create a local resource array with 2 elements. The second `ArraySubscriptExpr` is where `getArrayDecl` will be null because we hit the `OpaqueValueExpr` when looking for the decl, and it will be handled by Clang as a local array access on top of the local resource array that we created earlier. https://github.com/llvm/llvm-project/pull/154248 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits