Skip to content

Commit ce623b9

Browse files
committed
Fix lib assert/hang passing different struct with same layout to function (#2745)
1 parent 74c3b54 commit ce623b9

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,14 @@ void SROA_Helper::RewriteBitCast(BitCastInst *BCI) {
27432743
}
27442744

27452745
if (!bTypeMatch) {
2746+
// If the layouts match, just replace the type
2747+
SrcST = cast<StructType>(SrcTy);
2748+
if (SrcST->isLayoutIdentical(DstST)) {
2749+
BCI->mutateType(Val->getType());
2750+
BCI->replaceAllUsesWith(Val);
2751+
BCI->eraseFromParent();
2752+
return;
2753+
}
27462754
assert(0 && "Type mismatch.");
27472755
return;
27482756
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %dxc -T lib_6_x -default-linkage external %s | FileCheck %s
2+
3+
// CHECK: define <4 x float>
4+
// CHECK-SAME: main
5+
// CHECK-NOT: bitcast
6+
// CHECK-NOT: CallStruct
7+
// CHECK: ParamStruct
8+
// CHECK-NOT: bitcast
9+
// CHECK-NOT: CallStruct
10+
// CHECK-LABEL: ret <4 x float>
11+
12+
struct ParamStruct {
13+
int i;
14+
float f;
15+
};
16+
17+
struct CallStruct {
18+
int i;
19+
float f;
20+
};
21+
22+
void modify(inout ParamStruct s) {
23+
s.f += 1;
24+
}
25+
26+
void modify_ext(inout ParamStruct s);
27+
28+
CallStruct g_struct;
29+
30+
float4 main() : SV_Target {
31+
CallStruct local = g_struct;
32+
modify(local);
33+
modify_ext(local);
34+
return local.f;
35+
}

0 commit comments

Comments
 (0)