From c64fad8ef7ab196854112c4a65992b11510fde90 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 14 Jan 2026 00:43:06 +0100 Subject: Add warning for `size_of(&x)` expressions --- src/check_builtin.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/check_builtin.cpp') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 1b3e6912c..7b31314f8 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -2695,6 +2695,16 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As case BuiltinProc_size_of: { // size_of :: proc(Type or expr) -> untyped int + if (ce->args[0]->kind == Ast_UnaryExpr) { + ast_node(arg, UnaryExpr, ce->args[0]); + if (arg->op.kind == Token_And) { + ERROR_BLOCK(); + + warning(ce->args[0], "'size_of(&x)' returns the size of a pointer, not the size of x"); + error_line("\tSuggestion: Use 'size_of(rawptr)' if you want the size of the pointer"); + } + } + Operand o = {}; check_expr_or_type(c, &o, ce->args[0]); if (o.mode == Addressing_Invalid) { -- cgit v1.2.3 From ac35e0336b9c246673f1482ad907c013bfff7938 Mon Sep 17 00:00:00 2001 From: Franz Hoeltermann Date: Wed, 14 Jan 2026 10:42:43 +0100 Subject: Fix indentation --- src/check_builtin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/check_builtin.cpp') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 7b31314f8..929891826 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -2701,7 +2701,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As ERROR_BLOCK(); warning(ce->args[0], "'size_of(&x)' returns the size of a pointer, not the size of x"); - error_line("\tSuggestion: Use 'size_of(rawptr)' if you want the size of the pointer"); + error_line("\tSuggestion: Use 'size_of(rawptr)' if you want the size of the pointer"); } } -- cgit v1.2.3 From 92bef4578100e1bd4ca2e2ab9479216d8efcf2d3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 27 Jan 2026 09:44:52 +0000 Subject: Fix #6183 --- src/check_builtin.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/check_builtin.cpp') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 929891826..e732d8ec3 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -5383,6 +5383,14 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As return false; } } + if (!are_types_identical(x.type, y.type)) { + gbString xts = type_to_string(x.type); + gbString yts = type_to_string(y.type); + error(x.expr, "Mismatched types for '%.*s', got %s vs %s", LIT(builtin_name), xts, yts); + gb_string_free(yts); + gb_string_free(xts); + return false; + } operand->mode = Addressing_Value; operand->type = make_optional_ok_type(default_type(x.type)); @@ -5426,6 +5434,14 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As return false; } } + if (!are_types_identical(x.type, y.type)) { + gbString xts = type_to_string(x.type); + gbString yts = type_to_string(y.type); + error(x.expr, "Mismatched types for '%.*s', got %s vs %s", LIT(builtin_name), xts, yts); + gb_string_free(yts); + gb_string_free(xts); + return false; + } operand->mode = Addressing_Value; operand->type = default_type(x.type); -- cgit v1.2.3