Skip to content

Commit 527d58e

Browse files
authored
Handles empty embedded struct as first field of struct. (#3827)
Fixes #3770 Fixes #3016
1 parent 62a46db commit 527d58e

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4969,6 +4969,15 @@ void SROA_Parameter_HLSL::flattenArgument(
49694969
const std::string &semantic = annotation.GetSemanticString();
49704970
hlsl::InterpolationMode interpMode = annotation.GetInterpolationMode();
49714971

4972+
// Find index of first non-empty field.
4973+
unsigned firstNonEmptyIx = Elts.size();
4974+
for (unsigned ri = 0; ri < Elts.size(); ri++) {
4975+
if (DL.getTypeSizeInBits(Ty->getContainedType(ri)) > 0) {
4976+
firstNonEmptyIx = ri;
4977+
break;
4978+
}
4979+
}
4980+
49724981
// Push Elts into workList from right to left to preserve the order.
49734982
for (unsigned ri=0;ri<Elts.size();ri++) {
49744983
unsigned i = Elts.size() - ri - 1;
@@ -4981,10 +4990,12 @@ void SROA_Parameter_HLSL::flattenArgument(
49814990
Twine("semantic '") + eltSem + "' on field overridden by function or enclosing type");
49824991
}
49834992

4984-
// Inherit semantic from parent, but only preserve it for the first element.
4993+
// Inherit semantic from parent, but only preserve it for the first
4994+
// non-zero-sized element.
49854995
// Subsequent elements are noted with a special value that gets resolved
49864996
// once the argument is completely flattened.
4987-
EltAnnotation.SetSemanticString(i == 0 ? semantic : ContinuedPseudoSemantic);
4997+
EltAnnotation.SetSemanticString(
4998+
i == firstNonEmptyIx ? semantic : ContinuedPseudoSemantic);
49884999
} else if (!eltSem.empty() &&
49895000
semanticTypeMap.count(eltSem) == 0) {
49905001
Type *EltTy = dxilutil::GetArrayEltTy(Ty);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %dxc -E main -T vs_6_2 %s | FileCheck %s
2+
3+
struct s0 {};
4+
struct s1 { s0 a; uint b; };
5+
6+
// CHECK: ret
7+
s1 main() : OUT { s1 s; return s; }
8+

0 commit comments

Comments
 (0)