diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-07-08 16:34:16 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-07-08 16:34:16 +0200 |
commit | be6ffee58fb846512b1bb1edb085141b173f9b2e (patch) | |
tree | a71417fc1631cd56bd07a58baa32f8fad573aa34 | |
parent | 59ee1f6e4ec2f2ee240d34d9038baff47fecd834 (diff) |
Fix bugs when handling funcalls
-rw-r--r-- | src/analyzer.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/analyzer.c b/src/analyzer.c index 3683a68..b1c18e2 100644 --- a/src/analyzer.c +++ b/src/analyzer.c @@ -507,6 +507,8 @@ analyzeexpr(struct azctx *ctx, idx_t i) idx_t ni, lhs = ctx->ast.kids[i].lhs; ni = analyzeexpr(ctx, lhs); ctx->types[i] = ctx->types[lhs]->ret; + if (ctx->types[i] == NULL && ctx->ast.kinds[i - 1] != ASTCALLSTMT) + err("analyzer: Function without return type cannot be called in expression"); return ni; } default: @@ -575,6 +577,8 @@ constfoldstmt(struct azctx *ctx, idx_t i) case ASTASIGN: case ASTRET: return constfoldexpr(ctx, ctx->types[i], ctx->ast.kids[i].rhs); + case ASTCALLSTMT: + return constfoldexpr(ctx, ctx->types[i], i + 1); default: __builtin_unreachable(); } @@ -607,6 +611,7 @@ constfoldexpr(struct azctx *ctx, type_t *T, idx_t i) switch (ctx->ast.kinds[i]) { case ASTFUNCALL: /* TODO: Constfold funcall params */ + ni = fwdnode(ctx->ast, i); break; case ASTFN: return constfoldblk(ctx, ctx->ast.kids[i].rhs); @@ -849,6 +854,10 @@ out: __builtin_unreachable(); } + /* Expression has no type, such as a function call with no return value */ + if (ctx->types[i] == NULL) + return ni; + if (ctx->types[i]->kind == TYPE_NUM && TESTBIT(ctx->cnst, i) && !T->issigned && mpq_sgn(ctx->folds[i].q) == -1) { |