Browse Source

Take care CK_HLSLDerivedToBase in AggExprEmitter::VisitCastExpr. (#2312)

Xiang Li 6 years ago
parent
commit
5d5f293e5a

+ 1 - 0
tools/clang/lib/CodeGen/CGExprAgg.cpp

@@ -708,6 +708,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
     Visit(E->getSubExpr());
     break;
   // HLSL Change Begins.
+  case CK_HLSLDerivedToBase:
   case CK_FlatConversion: {
     QualType Ty = E->getSubExpr()->getType();
 

+ 37 - 0
tools/clang/test/CodeGenHLSL/batch/expressions/conversions_and_casts/derived_to_base_assign.hlsl

@@ -0,0 +1,37 @@
+// RUN: %dxc -E main -T vs_6_2 %s | FileCheck %s
+
+// Make sure (Base)v2p.b = (Base)d; create storeOutput.
+// CHECK:call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float
+// CHECK:call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 1, float
+// CHECK:call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 2, float
+// CHECK:call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 3, float
+
+
+struct Base
+{
+    float4 c : C;
+};
+
+struct Derived : Base
+{
+};
+
+
+struct VStoPS
+{
+    float4 a : A;
+    Derived b;
+    float4 p : SV_Position;
+};
+
+
+VStoPS main(float4 a : A, float4 b : B, float4 p : P)
+{
+    Derived d = (Derived)b;
+
+    VStoPS v2p;
+    v2p.a = a;
+    (Base)v2p.b = (Base)d;
+    v2p.p = p;
+    return v2p;
+}