Skip to content

Commit f587e00

Browse files
authored
[HLSL] Fix OpaqueValueExpr handling in InitListExpr (#156750)
The OpaqueValueVisitor was not correctly traversing the AST to find all OpaqueValueExprs. This resulted in some expressions not being correctly initialized. This change fixes the visitor to correctly traverse the AST. Fixes llvm/llvm-project#156786
1 parent 2bdcfc7 commit f587e00

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,27 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) {
863863

864864
class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> {
865865
public:
866-
llvm::SmallPtrSet<OpaqueValueExpr *, 8> OVEs;
866+
llvm::SmallVector<OpaqueValueExpr *, 8> OVEs;
867+
llvm::SmallPtrSet<OpaqueValueExpr *, 8> Visited;
867868
OpaqueValueVisitor() {}
868869

870+
bool VisitHLSLOutArgExpr(HLSLOutArgExpr *) {
871+
// These need to be bound in CodeGenFunction::EmitHLSLOutArgLValues
872+
// or CodeGenFunction::EmitHLSLOutArgExpr. If they are part of this
873+
// traversal, the temporary containing the copy out will not have
874+
// been created yet.
875+
return false;
876+
}
877+
869878
bool VisitOpaqueValueExpr(OpaqueValueExpr *E) {
870-
OVEs.insert(E);
879+
// Traverse the source expression first.
880+
if (E->getSourceExpr())
881+
TraverseStmt(E->getSourceExpr());
882+
883+
// Then add this OVE if we haven't seen it before.
884+
if (Visited.insert(E).second)
885+
OVEs.push_back(E);
886+
871887
return true;
872888
}
873889
};

clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -finclude-default-header \
22
// RUN: -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
33

4-
// https://github.com/llvm/llvm-project/issues/156786
5-
// XFAIL: *
6-
74
// This test verifies handling of multi-dimensional local arrays of resources
85
// when used as a function argument and local variable.
96

0 commit comments

Comments
 (0)