File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
test/CodeGenHLSL/BasicFeatures Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1313#include " CGCXXABI.h"
1414#include " CGCleanup.h"
1515#include " CGDebugInfo.h"
16+ #include " CGHLSLRuntime.h"
1617#include " CGObjCRuntime.h"
1718#include " CGOpenMPRuntime.h"
1819#include " CGRecordLayout.h"
@@ -2095,6 +2096,18 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
20952096 assert (Ignore == false && " init list ignored" );
20962097 unsigned NumInitElements = E->getNumInits ();
20972098
2099+ // HLSL initialization lists in the AST are an expansion which can contain
2100+ // side-effecting expressions wrapped in opaque value expressions. To properly
2101+ // emit these we need to emit the opaque values before we emit the argument
2102+ // expressions themselves. This is a little hacky, but it prevents us needing
2103+ // to do a bigger AST-level change for a language feature that we need
2104+ // deprecate in the near future. See related HLSL language proposals in the
2105+ // proposals (https://github.com/microsoft/hlsl-specs/blob/main/proposals):
2106+ // * 0005-strict-initializer-lists.md
2107+ // * 0032-constructors.md
2108+ if (CGF.getLangOpts ().HLSL )
2109+ CGF.CGM .getHLSLRuntime ().emitInitListOpaqueValues (CGF, E);
2110+
20982111 if (E->hadArrayRangeDesignator ())
20992112 CGF.ErrorUnsupported (E, " GNU array range designator extension" );
21002113
Original file line number Diff line number Diff line change @@ -941,3 +941,21 @@ FourFloats case16() {
941941 FourFloats FF = {0 , makeTwo (X), 3 };
942942 return FF;
943943}
944+
945+
946+ int case17Helper (int x) {
947+ return x;
948+ }
949+
950+ // InitList with OpaqueValueExpr
951+ // CHECK-LABEL: define void {{.*}}case17
952+ // CHECK: [[X:%.*]] = alloca <2 x i32>, align 8
953+ // CHECK-NEXT: [[C:%.*]] = call noundef i32 {{.*}}case17Helper{{.*}}(i32 noundef 0)
954+ // CHECK-NEXT: [[C1:%.*]] = call noundef i32 {{.*}}case17Helper{{.*}}(i32 noundef 1)
955+ // CHECK-NEXT: [[VI:%.*]] = insertelement <2 x i32> poison, i32 [[C]], i32 0
956+ // CHECK-NEXT: [[VI2:%.*]] = insertelement <2 x i32> [[VI]], i32 [[C1]], i32 1
957+ // CHECK-NEXT: store <2 x i32> [[VI2]], ptr [[X]], align 8
958+ // CHECK-NEXT: ret void
959+ void case17 () {
960+ int2 X = {case17Helper (0 ), case17Helper (1 )};
961+ }
You can’t perform that action at this time.
0 commit comments