diff --git a/src/compiler/ast.c b/src/compiler/ast.c index b7c974ed1..c166686fe 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -528,11 +528,11 @@ void fprint_expr_recursive(FILE *file, Expr *expr, int indent) case CONST_INT: if (expr->type->type_kind >= TYPE_U8 && expr->type->type_kind <= TYPE_UXX) { - fprintf(file, "%llu\n", expr->const_expr.i); + fprintf(file, "%llu\n", (unsigned long long)expr->const_expr.i); } else { - fprintf(file, "%lld\n", (int64_t)expr->const_expr.i); + fprintf(file, "%lld\n", (long long)expr->const_expr.i); } break; case CONST_FLOAT: diff --git a/src/compiler/diagnostics.c b/src/compiler/diagnostics.c index 0b0fda1cb..70a4c4ecd 100644 --- a/src/compiler/diagnostics.c +++ b/src/compiler/diagnostics.c @@ -30,7 +30,7 @@ static void print_error(SourceRange source_range, const char *message, PrintType { SourcePosition position = source_file_find_position(source_range.loc); - const static int LINES_SHOWN = 4; + static const int LINES_SHOWN = 4; unsigned max_line_length = (int)round(log10(position.line)) + 1; diff --git a/src/compiler/expr_analysis.c b/src/compiler/expr_analysis.c index 45d9e98bb..e1b76a24b 100644 --- a/src/compiler/expr_analysis.c +++ b/src/compiler/expr_analysis.c @@ -24,7 +24,7 @@ static bool expr_is_ltype(Expr *expr) || expr->identifier_expr.decl->var.kind == VARDECL_GLOBAL || expr->identifier_expr.decl->var.kind == VARDECL_PARAM); case EXPR_UNARY: - return expr->unary_expr.operator == TOKEN_STAR; + return expr->unary_expr.operator == UNARYOP_DEREF; case EXPR_ACCESS: return expr_is_ltype(expr->access_expr.parent); case EXPR_SUBSCRIPT: @@ -413,7 +413,7 @@ static inline Decl *decl_find_by_name(Decl** decls, const char *name) static inline bool expr_may_be_struct_field_decl(Expr *maybe_binary) { if (maybe_binary->expr_kind != EXPR_BINARY) return false; - if (maybe_binary->binary_expr.operator != TOKEN_EQ) return false; + if (maybe_binary->binary_expr.operator != BINARYOP_EQ) return false; Expr *expr = maybe_binary->binary_expr.left; while (1) { diff --git a/src/compiler/lexer.c b/src/compiler/lexer.c index 71119122b..d87ee81b4 100644 --- a/src/compiler/lexer.c +++ b/src/compiler/lexer.c @@ -221,6 +221,7 @@ void skip_whitespace(Lexer *lexer) { case '\n': lexer_store_line_end(lexer); + // fallthrough case ' ': case '\t': case '\r': diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index fd9e79cbd..dfb189154 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -240,6 +240,7 @@ LLVMValueRef gencontext_emit_unary_expr(GenContext *context, Expr *expr) case UNARYOP_DEC: return gencontext_emit_pre_inc_dec(context, expr->unary_expr.expr, -1, false); } + UNREACHABLE } @@ -430,6 +431,7 @@ static LLVMValueRef gencontext_emit_binary(GenContext *context, Expr *expr, LLVM case BINARYOP_SHL_ASSIGN: UNREACHABLE } + UNREACHABLE } LLVMValueRef gencontext_emit_post_unary_expr(GenContext *context, Expr *expr) diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index a872c2ed0..d5ba51296 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -201,7 +201,7 @@ void gencontext_emit_for_stmt(GenContext *context, Ast *ast) // A loop must either have a body or an inc. // This type of for loop is forbidden: // for (;;); - assert(cond_block || inc_block || body_block && "For has no body, no inc and no cond."); + assert((cond_block || inc_block || body_block) && "For has no body, no inc and no cond."); // Break is simple it always jumps out. // For continue: diff --git a/src/compiler/parser.c b/src/compiler/parser.c index 76339c9f3..53946691b 100644 --- a/src/compiler/parser.c +++ b/src/compiler/parser.c @@ -1598,6 +1598,7 @@ static Ast *parse_stmt(Context *context) sema_error_at(context->tok.span.loc - 1, "Reached the end of the file when expecting a statement."); return &poisoned_ast; } + UNREACHABLE } diff --git a/src/compiler/types.c b/src/compiler/types.c index 55e03face..cf00014f5 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -89,8 +89,8 @@ const char *type_to_error_string(Type *type) return buffer; case TYPE_ERROR_UNION: TODO - } + UNREACHABLE } static void type_append_signature_name_user_defined(Decl *decl, char *dst, size_t *offset) @@ -593,8 +593,11 @@ Type *type_find_max_type(Type *type, Type *other) case TYPE_SUBARRAY: TODO } + UNREACHABLE } +#define MAX_SEARCH_DEPTH 512 + Type *type_find_common_ancestor(Type *left, Type *right) { if (left == right) return left; @@ -609,7 +612,6 @@ Type *type_find_common_ancestor(Type *left, Type *right) } if (left->type_kind != TYPE_STRUCT) return NULL; - static const int MAX_SEARCH_DEPTH = 512; static Type *left_types[MAX_SEARCH_DEPTH]; int depth = 0; while (depth < MAX_SEARCH_DEPTH) diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index ee26f05dd..59fdd849b 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -150,23 +150,24 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi struct dirent *ent; while ((ent = readdir(dir))) { - if (ent->d_namlen < 4) continue; + size_t namelen = strlen(ent->d_name); + if (namelen < 4) continue; // Doesn't end with .c3 - if (strncmp(&ent->d_name[ent->d_namlen - 3], ".c3", 3) != 0) + if (strncmp(&ent->d_name[namelen - 3], ".c3", 3) != 0) { if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && recursive) { - char *new_path = strndup(ent->d_name, ent->d_namlen); + char *new_path = strndup(ent->d_name, namelen); file_add_wildcard_files(files, new_path, recursive); free(new_path); } continue; } - char *name = malloc_arena(ent->d_namlen + 1); - memcpy(name, ent->d_name, ent->d_namlen); - name[ent->d_namlen] = '\0'; + char *name = malloc_arena(namelen + 1); + memcpy(name, ent->d_name, namelen); + name[namelen] = '\0'; vec_add(*files, name); } closedir(dir); diff --git a/src/utils/toml.c b/src/utils/toml.c index d502239f8..7cb17fb76 100644 --- a/src/utils/toml.c +++ b/src/utils/toml.c @@ -38,11 +38,9 @@ char *toml_strndup(TOML_CONST char *str, size_t n) int toml_vasprintf(char **str, TOML_CONST char *format, va_list args) { - int size = 0; - va_list args_copy; va_copy(args_copy, args); - size = vsnprintf(NULL, size, format, args_copy); + int size = vsnprintf(NULL, 0, format, args_copy); va_end(args_copy); if (size < 0)