-
Notifications
You must be signed in to change notification settings - Fork 15k
[HLSL] Fix OpaqueValueExpr handling in InitListExpr #156750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Steven Perron (s-perron) ChangesThe OpaqueValueVisitor was not correctly traversing the AST to find all A test for this change will be included as part of the work in See discussion in Full diff: https://github.com/llvm/llvm-project/pull/156750.diff 1 Files Affected:
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;
}
};
|
@llvm/pr-subscribers-clang-codegen Author: Steven Perron (s-perron) ChangesThe OpaqueValueVisitor was not correctly traversing the AST to find all A test for this change will be included as part of the work in See discussion in Full diff: https://github.com/llvm/llvm-project/pull/156750.diff 1 Files Affected:
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;
}
};
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably remove the XFAIL from clang/test/CodeGenHLSL/BasicFeatures/InitLists.hls as part of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Failure are unrelated to my change. I can see the same failures on other PRs. |
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 #156786