commit 45dd46a199d8552edeec22a23730dde720d7b613
parent da0a098729a3d960c393e9cf7634e9a5c50e40f1
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 12 Aug 2021 07:49:31 +0200
check: don't create 0z bindings on propagate
Also re-enables tests/23-errors, which passes after this fix.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -1995,23 +1995,33 @@ check_expr_propagate(struct context *ctx,
ok_name.name = xcalloc(n + 1, 1);
snprintf(ok_name.name, n + 1, "ok.%d", ctx->id);
++ctx->id;
- const struct scope_object *ok_obj = scope_insert(scope, O_BIND,
- &ok_name, &ok_name, result_type, NULL);
+ const struct scope_object *ok_obj = NULL;
+ if (result_type->size != 0 && result_type->size != SIZE_UNDEFINED) {
+ ok_obj = scope_insert(scope, O_BIND, &ok_name,
+ &ok_name, result_type, NULL);
+ }
n = snprintf(NULL, 0, "err.%d", ctx->id);
err_name.name = xcalloc(n + 1, 1);
snprintf(err_name.name, n + 1, "err.%d", ctx->id);
++ctx->id;
- const struct scope_object *err_obj = scope_insert(scope, O_BIND,
- &err_name, &err_name, return_type, NULL);
+ const struct scope_object *err_obj = NULL;
+ if (return_type->size != 0 && return_type->size != SIZE_UNDEFINED) {
+ err_obj = scope_insert(scope, O_BIND, &err_name,
+ &err_name, return_type, NULL);
+ }
case_ok->type = result_type;
case_ok->object = ok_obj;
case_ok->value = xcalloc(1, sizeof(struct expression));
- case_ok->value->type = EXPR_ACCESS;
- case_ok->value->access.type = ACCESS_IDENTIFIER;
- case_ok->value->access.object = ok_obj;
case_ok->value->result = result_type;
+ if (ok_obj) {
+ case_ok->value->type = EXPR_ACCESS;
+ case_ok->value->access.type = ACCESS_IDENTIFIER;
+ case_ok->value->access.object = ok_obj;
+ } else {
+ case_ok->value->type = EXPR_CONSTANT;
+ }
case_err->type = return_type;
case_err->object = err_obj;
@@ -2043,10 +2053,14 @@ check_expr_propagate(struct context *ctx,
struct expression *rval =
xcalloc(1, sizeof(struct expression));
- rval->type = EXPR_ACCESS;
- rval->access.type = ACCESS_IDENTIFIER;
- rval->access.object = err_obj;
rval->result = return_type;
+ if (err_obj != NULL) {
+ rval->type = EXPR_ACCESS;
+ rval->access.type = ACCESS_IDENTIFIER;
+ rval->access.object = err_obj;
+ } else {
+ rval->type = EXPR_CONSTANT;
+ }
case_err->value->_return.value = lower_implicit_cast(
ctx->fntype->func.result, rval);
}
diff --git a/tests/configure b/tests/configure
@@ -61,6 +61,7 @@ EOF
19-append \
20-if \
21-tuples \
+ 23-errors \
24-imports \
25-promotion \
26-gen \
@@ -69,7 +70,6 @@ EOF
# Disabled tests
#22-delete \
- #23-errors \
#28-insert \
do
cat <<EOF