@@ -2072,10 +2072,6 @@ fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string {
20722072 }
20732073 }
20742074 }
2075- if sym.kind == .enum && sym.info is ast.Enum && sym.info.is_typedef {
2076- // @[typedef] enums are defined in a C header; use the original name without module prefix.
2077- styp = sym.name.all_after_last ('.' )
2078- }
20792075 return styp
20802076}
20812077
@@ -2923,10 +2919,19 @@ fn (mut g Gen) expr_with_tmp_var(expr ast.Expr, expr_typ ast.Type, ret_typ ast.T
29232919 }
29242920 }
29252921 }
2922+ // For @[heap] variables, the C-level variable is already a pointer
2923+ // even though the V-level type is a value type, so account for
2924+ // that extra indirection when computing how many '&' to add.
2925+ extra_muls := if expr is ast.Ident && g.resolved_ident_is_auto_heap (expr)
2926+ && ! expr_typ.is_ptr () {
2927+ 1
2928+ } else {
2929+ 0
2930+ }
29262931 if ! expr.is_literal () && expr_typ != ast.nil_type
2927- && ret_typ.nr_muls () > expr_typ.nr_muls ()
2932+ && ret_typ.nr_muls () > expr_typ.nr_muls () + extra_muls
29282933 && ! ret_typ.has_flag (.option_mut_param_t) {
2929- g.write ('&' .repeat (ret_typ.nr_muls () - expr_typ.nr_muls ()))
2934+ g.write ('&' .repeat (ret_typ.nr_muls () - expr_typ.nr_muls () - extra_muls ))
29302935 } else if ret_typ.has_flag (.option_mut_param_t) {
29312936 if expr_typ.is_ptr () {
29322937 if ret_typ.nr_muls () < expr_typ.nr_muls () {
@@ -6291,10 +6296,6 @@ fn (mut g Gen) debugger_stmt(node ast.DebuggerStmt) {
62916296}
62926297
62936298fn (mut g Gen) enum_decl (node ast.EnumDecl) {
6294- // @[typedef] enums are already defined in a C header, don't redefine them.
6295- if node.attrs.contains ('typedef' ) {
6296- return
6297- }
62986299 enum_name := util.no_dots (node.name)
62996300 is_flag := node.is_flag
63006301 // Explicit-size enums are emitted as typedef + defines, so all C compilers
0 commit comments