diff options
author | kugwa <kugwa2000@gmail.com> | 2015-12-11 15:23:12 +0800 |
---|---|---|
committer | kugwa <kugwa2000@gmail.com> | 2015-12-11 15:23:12 +0800 |
commit | 6a1784f1c85514c8b5ac529f8db7aed89a461291 (patch) | |
tree | d4c430ddfbfbfdc92bcadb52faa6ab24f0033ce6 | |
parent | 911d19623ae4aca89b5fade6ae6be15d45ac05af (diff) | |
download | compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar.gz compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar.bz2 compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar.lz compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar.xz compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.tar.zst compiler2015-6a1784f1c85514c8b5ac529f8db7aed89a461291.zip |
Fix error detection in check_call()
Additional changes:
Fix crash when excuting statement "return; " in a function with return type "void"
-rw-r--r-- | src/semantic-analysis.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c index ecfca31..121027d 100644 --- a/src/semantic-analysis.c +++ b/src/semantic-analysis.c @@ -421,34 +421,39 @@ static bool check_call(CcmmcAst *call, CcmmcSymbolTable *table) if (param_sym == NULL) { fprintf(stderr, ERROR("ID `%s' undeclared."), param->line_number, param->value_id.name); + any_error = true; continue; } if (param_sym->kind != CCMMC_SYMBOL_KIND_VARIABLE) { fprintf(stderr, ERROR("ID `%s' is not a variable."), param->line_number, param_sym->name); + any_error = true; continue; } size_t dim; any_error = check_array_subscript(param, table, &dim) || any_error; if (dim > param_sym->type.array_dimension) { fprintf(stderr, ERROR("Incompatible array dimensions."), param->line_number); + any_error = true; continue; } if (func->type.param_list[i].array_dimension == 0 && dim < param_sym->type.array_dimension) { fprintf(stderr, ERROR("Array `%s' passed to scalar parameter %zu."), param->line_number, param_sym->name, i); + any_error = true; continue; } if (func->type.param_list[i].array_dimension != 0 && dim == param_sym->type.array_dimension) { fprintf(stderr, ERROR("Scalar `%s' passed to array parameter %zu."), param->line_number, param_sym->name, i); + any_error = true; continue; } } else { - check_relop_expr(param, table); + any_error = check_relop_expr(param, table) || any_error; } } @@ -811,10 +816,10 @@ static bool process_statement(CcmmcAst *stmt, CcmmcSymbolTable *table) break; } } - if (stmt->child == NULL && - func_sym->type.type_base != CCMMC_AST_VALUE_VOID) { - fprintf(stderr, WARNING("Incompatible return type."), - stmt->line_number); + if (stmt->child == NULL) { + if (func_sym->type.type_base != CCMMC_AST_VALUE_VOID) + fprintf(stderr, WARNING("Incompatible return type."), + stmt->line_number); } else { any_error = check_relop_expr(stmt->child, table) || any_error; |