-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL] Handle init list with OpaqueValueExprs in CGExprScalar #138541
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-hlsl Author: Sarah Spall (spall) ChangesWhen an HLSL Init list is producing a Scalar, handle OpaqueValueExprs in the Init List with 'emitInitListOpaqueValues' Full diff: https://github.com/llvm/llvm-project/pull/138541.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 15a6177746403..c4d7409d212cf 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -13,6 +13,7 @@
#include "CGCXXABI.h"
#include "CGCleanup.h"
#include "CGDebugInfo.h"
+#include "CGHLSLRuntime.h"
#include "CGObjCRuntime.h"
#include "CGOpenMPRuntime.h"
#include "CGRecordLayout.h"
@@ -2095,6 +2096,17 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
assert (Ignore == false && "init list ignored");
unsigned NumInitElements = E->getNumInits();
+ // HLSL initialization lists in the AST are an expansion which can contain
+ // side-effecting expressions wrapped in opaque value expressions. To properly
+ // emit these we need to emit the opaque values before we emit the argument
+ // expressions themselves. This is a little hacky, but it prevents us needing
+ // to do a bigger AST-level change for a language feature that we need
+ // deprecate in the near future. See related HLSL language proposals:
+ // * 0005-strict-initializer-lists.md
+ // * https://github.com/microsoft/hlsl-specs/pull/325
+ if (CGF.getLangOpts().HLSL)
+ CGF.CGM.getHLSLRuntime().emitInitListOpaqueValues(CGF, E);
+
if (E->hadArrayRangeDesignator())
CGF.ErrorUnsupported(E, "GNU array range designator extension");
diff --git a/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl
index d04583e4fc51a..93246d326734a 100644
--- a/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl
+++ b/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl
@@ -941,3 +941,21 @@ FourFloats case16() {
FourFloats FF = {0, makeTwo(X), 3};
return FF;
}
+
+
+int case17Helper(int x) {
+ return x;
+}
+
+// InitList with OpaqueValueExpr
+// CHECK-LABEL: define void {{.*}}case17
+// CHECK: [[X:%.*]] = alloca <2 x i32>, align 8
+// CHECK-NEXT: [[C:%.*]] = call noundef i32 {{.*}}case17Helper{{.*}}(i32 noundef 0)
+// CHECK-NEXT: [[C1:%.*]] = call noundef i32 {{.*}}case17Helper{{.*}}(i32 noundef 1)
+// CHECK-NEXT: [[VI:%.*]] = insertelement <2 x i32> poison, i32 [[C]], i32 0
+// CHECK-NEXT: [[VI2:%.*]] = insertelement <2 x i32> [[VI]], i32 [[C1]], i32 1
+// CHECK-NEXT: store <2 x i32> [[VI2]], ptr [[X]], align 8
+// CHECK-NEXT: ret void
+void case17() {
+ int2 X = {case17Helper(0), case17Helper(1)};
+}
\ No newline at end of file
|
llvm-beanz
reviewed
May 5, 2025
llvm-beanz
approved these changes
May 5, 2025
farzonl
approved these changes
May 5, 2025
Co-authored-by: Chris B <beanz@abolishcrlf.org>
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…38541) When an HLSL Init list is producing a Scalar, handle OpaqueValueExprs in the Init List with 'emitInitListOpaqueValues' Copied from 'AggExprEmitter::VisitCXXParenListOrInitListExpr' Closes llvm#136408 --------- Co-authored-by: Chris B <beanz@abolishcrlf.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
HLSL
HLSL Language Support
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an HLSL Init list is producing a Scalar, handle OpaqueValueExprs in the Init List with 'emitInitListOpaqueValues'
Copied from 'AggExprEmitter::VisitCXXParenListOrInitListExpr'
Closes #136408