Skip to content

Commit 3fa3bc0

Browse files
committed
[HLSL] Fix OpaqueValueExpr handling in InitListExpr
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. A test for this change will be included as part of the work in llvm#156075. See discussion in https://github.com/llvm/llvm-project/pull/156075/files#r2317231524.
1 parent 51163c5 commit 3fa3bc0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

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

829829
class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> {
830830
public:
831-
llvm::SmallPtrSet<OpaqueValueExpr *, 8> OVEs;
831+
llvm::SmallVector<OpaqueValueExpr *, 8> OVEs;
832+
llvm::SmallPtrSet<OpaqueValueExpr *, 8> Visited;
832833
OpaqueValueVisitor() {}
833834

835+
bool VisitHLSLOutArgExpr(HLSLOutArgExpr *) {
836+
// These need to be bound in CodeGenFunction::EmitHLSLOutArgLValues
837+
// or CodeGenFunction::EmitHLSLOutArgExpr. If they are part of this
838+
// traversal, the temporary containing the copy out will not have
839+
// been created yet.
840+
return false;
841+
}
842+
834843
bool VisitOpaqueValueExpr(OpaqueValueExpr *E) {
835-
OVEs.insert(E);
844+
// Traverse the source expression first.
845+
if (E->getSourceExpr())
846+
TraverseStmt(E->getSourceExpr());
847+
848+
// Then add this OVE if we haven't seen it before.
849+
if (Visited.insert(E).second)
850+
OVEs.push_back(E);
851+
836852
return true;
837853
}
838854
};

0 commit comments

Comments
 (0)