Sfoglia il codice sorgente

Fix lib assert/hang passing different struct with same layout to function (#2745)

Tex Riddell 5 anni fa
parent
commit
39efc1c762

+ 8 - 0
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -2743,6 +2743,14 @@ void SROA_Helper::RewriteBitCast(BitCastInst *BCI) {
   }
   }
 
 
   if (!bTypeMatch) {
   if (!bTypeMatch) {
+    // If the layouts match, just replace the type
+    SrcST = cast<StructType>(SrcTy);
+    if (SrcST->isLayoutIdentical(DstST)) {
+      BCI->mutateType(Val->getType());
+      BCI->replaceAllUsesWith(Val);
+      BCI->eraseFromParent();
+      return;
+    }
     assert(0 && "Type mismatch.");
     assert(0 && "Type mismatch.");
     return;
     return;
   }
   }

+ 35 - 0
tools/clang/test/HLSLFileCheck/shader_targets/library/inout_struct_mismatch.hlsl

@@ -0,0 +1,35 @@
+// RUN: %dxc -T lib_6_x -default-linkage external %s | FileCheck %s
+
+// CHECK: define <4 x float>
+// CHECK-SAME: main
+// CHECK-NOT: bitcast
+// CHECK-NOT: CallStruct
+// CHECK: ParamStruct
+// CHECK-NOT: bitcast
+// CHECK-NOT: CallStruct
+// CHECK-LABEL: ret <4 x float>
+
+struct ParamStruct {
+  int i;
+  float f;
+};
+
+struct CallStruct {
+  int i;
+  float f;
+};
+
+void modify(inout ParamStruct s) {
+  s.f += 1;
+}
+
+void modify_ext(inout ParamStruct s);
+
+CallStruct g_struct;
+
+float4 main() : SV_Target {
+  CallStruct local = g_struct;
+  modify(local);
+  modify_ext(local);
+  return local.f;
+}