From 213831289afaa22f397ee8b469e3082a247963ed Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Mon, 4 Nov 2024 04:20:14 +0500 Subject: [PATCH] Fix compile with gcc 14.2.1 (#1594) * Fix compile with gcc 14.2.1 Fixes -Werror=maybe-uninitialized warnings * Updated to use INVALID_PTR rather than NULL. --------- Co-authored-by: Christoffer Lerno --- src/compiler/compiler_internal.h | 2 ++ src/compiler/llvm_codegen_expr.c | 2 +- src/compiler/sema_expr.c | 4 ++-- src/compiler/sema_initializers.c | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 451e82278..a69c9bd00 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -71,6 +71,8 @@ typedef uint16_t FileId; #define EXPAND_EXPR_STRING(str_) (str_)->const_expr.bytes.len, (str_)->const_expr.bytes.ptr #define TABLE_MAX_LOAD 0.5 +#define INVALID_PTR ((void*)(uintptr_t)0xAAAAAAAAAAAAAAAA) + typedef struct Ast_ Ast; typedef struct Decl_ Decl; typedef struct TypeInfo_ TypeInfo; diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 368a92961..09c88c4e5 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -2967,7 +2967,7 @@ static void llvm_emit_slice_values(GenContext *c, Expr *slice, BEValue *parent_r // Emit the start and end - Type *start_type; + Type *start_type = (Type*)INVALID_PTR; Range range = slice->slice_expr.range; BEValue start_index; switch (range.range_type) diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index fba16a913..d7a0f2a4c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1557,7 +1557,7 @@ INLINE bool sema_call_evaluate_arguments(SemaContext *context, CalledDecl *calle bool has_named = false; bool found_splat = false; ArrayIndex last_index = -1; - Expr *last_named_arg; + Expr *last_named_arg = INVALID_PTR; Expr *last = NULL; int needed = func_param_count - (callee->struct_var ? 1 : 0); for (unsigned i = 0; i < num_args; i++) @@ -4280,7 +4280,7 @@ static bool sema_expr_rewrite_to_typeid_property(SemaContext *context, Expr *exp static inline bool sema_expr_fold_to_index(Expr *expr, Expr *parent, SubscriptIndex index_expr) { ConstInitializer *init = parent->const_expr.initializer; - ConstInitializer *result; + ConstInitializer *result = INVALID_PTR; ASSERT_SPAN(expr, !index_expr.start_from_end); ArrayIndex index = exprptr(index_expr.expr)->const_expr.ixx.i.low; switch (init->kind) diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index 23392cbf7..d26ff2712 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -42,8 +42,8 @@ static inline void sema_update_const_initializer_with_designator( bool const_init_local_init_may_be_global_inner(ConstInitializer *init, bool top) { - ConstInitializer **list; - unsigned len; + ConstInitializer **list = INVALID_PTR; + unsigned len = (unsigned)-1; switch (init->kind) { case CONST_INIT_ZERO: @@ -1318,3 +1318,4 @@ static Decl *sema_resolve_element_for_name(SemaContext *context, Decl **decls, D (*index)++; return found; } +