Zebediah Figura : d3dcompiler: Parse return statements without a value.

Alexandre Julliard julliard at winehq.org
Tue Mar 3 16:24:53 CST 2020


Module: wine
Branch: master
Commit: e597b9e5554f05287377233233adc370449667d7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e597b9e5554f05287377233233adc370449667d7

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Sun Mar  1 22:55:24 2020 -0600

d3dcompiler: Parse return statements without a value.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3dcompiler_43/hlsl.y            | 55 +++++++++++++++++++++++++----------
 dlls/d3dcompiler_43/tests/hlsl_d3d9.c |  2 +-
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index b6478bf3fe..0f9676df16 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -481,6 +481,28 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const cha
     return NULL;
 }
 
+static struct hlsl_ir_jump *new_return(struct hlsl_ir_node *value, struct source_location loc)
+{
+    struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump));
+    if (!jump)
+    {
+        ERR("Out of memory\n");
+        return NULL;
+    }
+    jump->node.type = HLSL_IR_JUMP;
+    jump->node.loc = loc;
+    jump->type = HLSL_IR_JUMP_RETURN;
+    jump->node.data_type = value ? value->data_type
+            : new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
+    jump->return_value = value;
+
+    FIXME("Check for valued return on void function.\n");
+    FIXME("Implicit conversion to the return type if needed, "
+            "error out if conversion not possible.\n");
+
+    return jump;
+}
+
 static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var,
         struct parse_initializer *initializer)
 {
@@ -1769,28 +1791,31 @@ statement:                declaration_statement
                         | selection_statement
                         | loop_statement
 
-                          /* FIXME: add rule for return with no value */
 jump_statement:           KW_RETURN expr ';'
                             {
-                                struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump));
-                                if (!jump)
-                                {
-                                    ERR("Out of memory\n");
-                                    YYABORT;
-                                }
-                                jump->node.type = HLSL_IR_JUMP;
-                                set_location(&jump->node.loc, &@1);
-                                jump->type = HLSL_IR_JUMP_RETURN;
-                                jump->node.data_type = node_from_list($2)->data_type;
-                                jump->return_value = node_from_list($2);
+                                struct source_location loc;
+                                struct hlsl_ir_jump *jump;
 
-                                FIXME("Check for valued return on void function.\n");
-                                FIXME("Implicit conversion to the return type if needed, "
-				        "error out if conversion not possible.\n");
+                                set_location(&loc, &@1);
+                                if (!(jump = new_return(node_from_list($2), loc)))
+                                    YYABORT;
 
                                 $$ = $2;
                                 list_add_tail($$, &jump->node.entry);
                             }
+                        | KW_RETURN ';'
+                            {
+                                struct source_location loc;
+                                struct hlsl_ir_jump *jump;
+
+                                set_location(&loc, &@1);
+                                if (!(jump = new_return(NULL, loc)))
+                                    YYABORT;
+
+                                $$ = d3dcompiler_alloc(sizeof(*$$));
+                                list_init($$);
+                                list_add_tail($$, &jump->node.entry);
+                            }
 
 selection_statement:      KW_IF '(' expr ')' if_body
                             {
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
index 062ef0a84a..f1ce5dc5bc 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -730,7 +730,7 @@ static void test_fail(void)
             compiled = errors = NULL;
             hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors);
             todo_wine ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr);
-            todo_wine_if (i == 1 || i >= 8) ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]);
+            todo_wine_if (i == 1 || i >= 7) ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]);
             ok(!compiled, "Test %u, target %s, expected no compiled shader blob.\n", i, targets[j]);
             if (errors)
                 ID3D10Blob_Release(errors);




More information about the wine-cvs mailing list