Skip to content

Commit 02e0a95

Browse files
spallllvm-beanz
andauthored
[HLSL] Handle init list with OpaqueValueExprs in CGExprScalar (#138541)
When an HLSL Init list is producing a Scalar, handle OpaqueValueExprs in the Init List with 'emitInitListOpaqueValues' Copied from 'AggExprEmitter::VisitCXXParenListOrInitListExpr' Closes #136408 --------- Co-authored-by: Chris B <beanz@abolishcrlf.org>
1 parent 1ff2953 commit 02e0a95

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)