From 20197ee0bc721b03b6121e2065a206446f1ac64d Mon Sep 17 00:00:00 2001 From: BrainStackOverFlow <48990146+BrainStackOverFlow@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:00:59 +0300 Subject: [PATCH] Fix unhandled AST_EXPR_EXT_SIZEOF Error --- src/ast.c | 4 ++++ src/utils.h | 8 ++++++++ src/x86/cg.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ast.c b/src/ast.c index 72164bd..2928784 100644 --- a/src/ast.c +++ b/src/ast.c @@ -396,6 +396,10 @@ static void ast_usedef_pass(AST *tlc, AST *a, AST *wholestmt) { if(a->stmtReturn.val) { ast_usedef_pass(tlc, a->stmtReturn.val, wholestmt); } + } else if (a->nodeKind == AST_EXPR_EXT_SIZEOF) { + if (a->exprExtSizeOf.ofExpr) { + ast_usedef_pass(tlc, a->exprExtSizeOf.ofExpr, wholestmt); + } } else { stahp_node(a, "ast_usedef_pass: unhandled %s", AST_KIND_STR[a->nodeKind]); } diff --git a/src/utils.h b/src/utils.h index e3d3f5a..abf9b7a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,6 +7,7 @@ #include #include #include +#include inline static size_t djb2(const char *str) { size_t hash = 5381; @@ -54,4 +55,11 @@ __attribute__((format(printf, 1, 2))) static inline char *malp(const char *fmt, return str; } +inline static int is_str_equal_check_null(const char *s1, const char *s2) { + if (!s1 || !s2) { + return 0; + } + return !strcmp(s1, s2); +} + #endif diff --git a/src/x86/cg.c b/src/x86/cg.c index cf21819..5cee188 100644 --- a/src/x86/cg.c +++ b/src/x86/cg.c @@ -333,7 +333,7 @@ void cg_chunk(CGState *cg, AST *a) { } else if(s->nodeKind == AST_STMT_ASSIGN) { - if(s->stmtAssign.to && is_xop(s->stmtAssign.what) == XOP_NOT_MEM && is_xop(s->stmtAssign.to) == XOP_NOT_MEM && !strcmp(xop(cg->tlc, s->stmtAssign.what), xop(cg->tlc, s->stmtAssign.to))) { + if(s->stmtAssign.to && is_xop(s->stmtAssign.what) == XOP_NOT_MEM && is_xop(s->stmtAssign.to) == XOP_NOT_MEM && is_str_equal_check_null(xop(cg->tlc, s->stmtAssign.what), xop(cg->tlc, s->stmtAssign.to))) { // It's a noop } else if(s->stmtAssign.to) { if(x86_imul_supported() && s->stmtAssign.to->nodeKind == AST_EXPR_BINARY_OP && s->stmtAssign.to->exprBinOp.operator == BINOP_MUL) {