@@ -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);
0 commit comments