diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index d27f3781c69a3..b6e5e57c541a8 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -829,11 +829,27 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) { class OpaqueValueVisitor : public RecursiveASTVisitor { public: - llvm::SmallPtrSet OVEs; + llvm::SmallVector OVEs; + llvm::SmallPtrSet Visited; OpaqueValueVisitor() {} + bool VisitHLSLOutArgExpr(HLSLOutArgExpr *) { + // These need to be bound in CodeGenFunction::EmitHLSLOutArgLValues + // or CodeGenFunction::EmitHLSLOutArgExpr. If they are part of this + // traversal, the temporary containing the copy out will not have + // been created yet. + return false; + } + bool VisitOpaqueValueExpr(OpaqueValueExpr *E) { - OVEs.insert(E); + // Traverse the source expression first. + if (E->getSourceExpr()) + TraverseStmt(E->getSourceExpr()); + + // Then add this OVE if we haven't seen it before. + if (Visited.insert(E).second) + OVEs.push_back(E); + return true; } }; diff --git a/clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl b/clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl index 7956e40de1438..92dba219f2295 100644 --- a/clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl +++ b/clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl @@ -1,9 +1,6 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -finclude-default-header \ // RUN: -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s -// https://github.com/llvm/llvm-project/issues/156786 -// XFAIL: * - // This test verifies handling of multi-dimensional local arrays of resources // when used as a function argument and local variable.