瀏覽代碼

Improve derived to base assignment test (#2313)

The original test succeeded even in the presence of the bug whose fix it was trying to verify. I've further simplified it and added more cases for different combinations of LHS/RHS conversions and casts.
Tristan Labelle 6 年之前
父節點
當前提交
a5277ac51e

+ 32 - 30
tools/clang/test/CodeGenHLSL/batch/expressions/conversions_and_casts/derived_to_base_assign.hlsl

@@ -1,37 +1,39 @@
 // RUN: %dxc -E main -T vs_6_2 %s | FileCheck %s
 // 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
+// Test assignments to and from the base class part of an object only.
 
 
-
-struct Base
-{
-    float4 c : C;
-};
-
-struct Derived : Base
-{
-};
-
-
-struct VStoPS
+struct Base { int i; };
+struct Derived : Base { int j; };
+struct Output
 {
 {
-    float4 a : A;
-    Derived b;
-    float4 p : SV_Position;
+    Derived d0;
+    Derived d1;
+    Base b0;
+    Base b1;
 };
 };
 
 
-
-VStoPS main(float4 a : A, float4 b : B, float4 p : P)
+Output main(Derived d : IN) : OUT
 {
 {
-    Derived d = (Derived)b;
-
-    VStoPS v2p;
-    v2p.a = a;
-    (Base)v2p.b = (Base)d;
-    v2p.p = p;
-    return v2p;
-}
+    // Use CHECK-DAG because there are actually storeOutputs for both the zero initialization and the final value.
+    Output output = (Output)0;
+
+    // With LHS cast and implicit RHS conversion (derived field untouched)
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 0, i32 0, i8 0, i32 %{{.*}})
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 1, i32 0, i8 0, i32 0)
+    (Base)output.d0 = d;
+    
+    // With LHS and RHS cast (derived field untouched)
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 2, i32 0, i8 0, i32 %{{.*}})
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 3, i32 0, i8 0, i32 0)
+    (Base)output.d1 = (Base)d;
+    
+    // With implicit RHS conversion
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 4, i32 0, i8 0, i32 %{{.*}})
+    output.b0 = d;
+    
+    // With RHS cast
+    // CHECK-DAG: call void @dx.op.storeOutput.i32(i32 5, i32 5, i32 0, i8 0, i32 %{{.*}})
+    output.b1 = (Base)d;
+
+    return output;
+}