[clang] [HLSL] Fix OpaqueValueExpr handling in InitListExpr (PR #156750)
Steven Perron via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 8 13:05:38 PDT 2025
https://github.com/s-perron updated https://github.com/llvm/llvm-project/pull/156750
>From 3fa3bc0ae3e3f24368d7ffeed2595580d0e982a1 Mon Sep 17 00:00:00 2001
From: Steven Perron <stevenperron at google.com>
Date: Wed, 3 Sep 2025 16:09:17 -0400
Subject: [PATCH 1/2] [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
https://github.com/llvm/llvm-project/pull/156075.
See discussion in
https://github.com/llvm/llvm-project/pull/156075/files#r2317231524.
---
clang/lib/CodeGen/CGHLSLRuntime.cpp | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 442d8505cc0ed..c5660bc518712 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -828,11 +828,27 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) {
class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> {
public:
- llvm::SmallPtrSet<OpaqueValueExpr *, 8> OVEs;
+ llvm::SmallVector<OpaqueValueExpr *, 8> OVEs;
+ llvm::SmallPtrSet<OpaqueValueExpr *, 8> 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;
}
};
>From 7e3c19875bda7714a1302245fcc21c1e6eb19bbe Mon Sep 17 00:00:00 2001
From: Steven Perron <stevenperron at google.com>
Date: Mon, 8 Sep 2025 16:05:19 -0400
Subject: [PATCH 2/2] Reenable test that was fixed.
---
.../test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl | 3 ---
1 file changed, 3 deletions(-)
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.
More information about the cfe-commits
mailing list