Casting a fault to a pointer would trigger an assert.

This commit is contained in:
Christoffer Lerno
2025-07-05 01:38:44 +02:00
parent 50efc95c83
commit b19cd0b87d
8 changed files with 8 additions and 13 deletions

View File

@@ -26,6 +26,7 @@
- Const slice indexing was not bounds checked.
- Initialize pool correctly in print_backtrace.
- `--max-mem` now works correctly again.
- Casting a fault to a pointer would trigger an assert.
### Stdlib changes

View File

@@ -2573,7 +2573,6 @@ INLINE Type *type_vector_type(Type *type);
static inline CanonicalType *type_pointer_type(Type *type);
static inline CanonicalType *type_flatten(Type *type);
static inline bool type_flat_is_char_array(Type *type);
static inline Type *type_base(Type *type);
INLINE TypeInfo *type_info_new(TypeInfoKind kind, SourceSpan span);
@@ -3498,8 +3497,6 @@ static inline void expr_set_span(Expr *expr, SourceSpan loc)
default:
return;
}
expr_list_set_span(expr->expression_list, loc);
return;
case EXPR_CAST:
exprid_set_span(expr->cast_expr.expr, loc);
return;
@@ -4240,9 +4237,9 @@ INLINE bool check_module_name(Path *path)
}
#ifdef NDEBUG
#define ASSERT_SPANF(node__, check__, format__, ...) do { } while(0)
#define ASSERT_SPAN(node__, check__) do { } while(0)
#define ASSERT_AT(span__, check__) do { } while(0)
#define ASSERT_SPANF(node__, check__, format__, ...) do { (void)(check__); } while(0)
#define ASSERT_SPAN(node__, check__) do { (void)(check__); } while(0)
#define ASSERT_AT(span__, check__) do { (void)(check__);} while(0)
#else
#define ASSERT_SPANF(node__, check__, format__, ...) do { if (!(check__)) { assert_print_line((node__)->span); eprintf(format__, __VA_ARGS__); ASSERT(check__); } } while(0)
#define ASSERT_SPAN(node__, check__) do { if (!(check__)) { assert_print_line((node__)->span); ASSERT(check__); } } while(0)

View File

@@ -75,7 +75,6 @@ static void print_error_type_at(SourceSpan location, const char *message, PrintT
}
else if (compiler.build.test_output || compiler.build.benchmark_output)
{
bool ansi = use_ansi();
switch (print_type)
{
case PRINT_TYPE_ERROR:

View File

@@ -260,7 +260,7 @@ typedef enum FLAG_ATTR
#define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT)
#define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO | ATTR_FNTYPE)
#define USER_DEFINED_TYPES EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT
#define USER_DEFINED_TYPES (EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT)
typedef enum
{

View File

@@ -556,7 +556,6 @@ RETRY:
TODO;
case TYPE_FUNC_RAW:
UNREACHABLE
return;
case TYPE_STRUCT:
case TYPE_UNION:
header_gen_struct_union_top(c, type->decl, is_pointer ? GEN_POINTER : GEN_FULL);

View File

@@ -1854,6 +1854,7 @@ static void cast_int_to_enum(Expr *expr, Type *type)
{
Int to_convert = expr->const_expr.ixx;
unsigned max_enums = vec_size(decl->enums.values);
(void)max_enums;
assert(max_enums > to_convert.i.low);
expr->expr_kind = EXPR_CONST;
expr->const_expr = (ExprConst) {
@@ -2499,7 +2500,7 @@ CastFunction cast_function[CONV_LAST + 1][CONV_LAST + 1] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // CONST ENUM
{XX2VO, 0, PT2BO, PT2IN, 0, 0, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, PT2PT, 0, 0, PT2PT, 0, 0, 0 }, // FUNC
{XX2VO, 0, TI2BO, TI2IN, 0, TI2PT, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TI2PT, TI2PT, 0, 0 }, // TYPEID
{XX2VO, 0, AF2BO, FA2IN, 0, FA2IN, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FA2IN, FA2IN, 0, 0 }, // ANYFAULT
{XX2VO, 0, AF2BO, FA2IN, 0, FA2PT, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FA2IN, FA2IN, 0, 0 }, // ANYFAULT
{XX2VO, 0, PT2BO, PT2IN, 0, PT2PT, 0, EX2VC, 0, 0, 0, 0, 0, PT2AY, PT2AY, 0, 0, PT2PT, 0, 0, 0, PT2PT, 0, 0 }, // VOIDPTR
{XX2VO, 0, PT2BO, PT2IN, 0, PT2PT, AP2SL, EX2VC, 0, 0, 0, 0, 0, PT2AY, PT2AY, 0, 0, 0, 0, 0, PT2PT, PT2PT, PT2FE, 0 }, // ARRAYPTR
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // INFERRED

View File

@@ -6659,7 +6659,7 @@ static bool sema_binary_analyse_ct_subscript_op_assign(SemaContext *context, Exp
ArrayIndex idx = left->ct_subscript_expr.index;
Expr *lhs_expr = left_var->var.init_expr;
ASSERT_SPAN(lhs_expr, lhs_expr->expr_kind == EXPR_CONST);
Expr *value = expr_from_const_expr_at_index(left_var->var.init_expr, idx);
Expr *value = expr_from_const_expr_at_index(lhs_expr, idx);
BinaryOp op = binaryop_assign_base_op(expr->binary_expr.operator);
expr->binary_expr = (ExprBinary) { .left = exprid(value), .right = expr->binary_expr.right, .operator = op };

View File

@@ -278,8 +278,6 @@ JSONObject *json_parse_array(JsonParser *parser)
return array;
}
size_t capacity = 16;
size_t index = 0;
while (1)
{
JSONObject *parsed = json_parse(parser);