From 65ba81981bc06ec32da8a1a19a26494e01fdf5bc Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 8 May 2026 02:19:42 +0300 Subject: [PATCH] cgen: tcc fixes --- vlib/v/checker/struct.v | 5 ++++- vlib/v/gen/c/cgen.v | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 94e71bb39..aaee12d23 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -131,7 +131,10 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { // Overwrite the previously unresolved type symbol so that earlier // expressions which captured its idx (e.g. IndexExpr.left_type from // another file checked first) observe the resolved size. See #27078. - if old_typ.idx() != field.typ.idx() { + // Skip for generic structs: the size expression may reference a generic + // type parameter (e.g. `sizeof(T)`), which resolves to a placeholder size + // here; the correct per-instantiation size is computed later in struct_init. + if old_typ.idx() != field.typ.idx() && struct_sym.info.generic_types.len == 0 { new_sym := c.table.sym(field.typ) mut old_sym := c.table.type_symbols[old_typ.idx()] old_sym.name = new_sym.name diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index b12e7e61b..74011cc36 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -13082,6 +13082,9 @@ fn (mut g Gen) panic_debug_info(pos token.Pos) (int, string, string, string) { // when available, or emits `imessage` through a C error otherwise. pub fn get_guarded_include_text(iname string, imessage string) string { res := ' + |#ifdef __TINYC__ + |#include ${iname} + |#else |#if defined(__has_include) |#if __has_include(${iname}) |#include ${iname} @@ -13091,6 +13094,7 @@ pub fn get_guarded_include_text(iname string, imessage string) string { |#else |#include ${iname} |#endif + |#endif '.strip_margin() return res } @@ -13099,6 +13103,9 @@ pub fn get_guarded_include_text(iname string, imessage string) string { // the best available integer types header, or emits `imessage` otherwise. pub fn get_inttypes_or_stdint_include_text(imessage string) string { res := ' + |#ifdef __TINYC__ + |#include + |#else |#if defined(__has_include) |#if __has_include() |#include @@ -13110,6 +13117,7 @@ pub fn get_inttypes_or_stdint_include_text(imessage string) string { |#else |#include |#endif + |#endif '.strip_margin() return res } -- 2.39.5