From a8be1f8037e557708f7e288a8ea950269f418300 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sun, 6 Mar 2022 18:28:16 +0200 Subject: [PATCH] cxgo: properly unwrap new value when using calloc --- pointers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pointers.go b/pointers.go index 1e97b69..54801d6 100644 --- a/pointers.go +++ b/pointers.go @@ -208,6 +208,14 @@ func (g *translator) cAddr(x Expr) PtrExpr { return g.ToPointer(x) } if xt.Kind().Is(types.Array) { + if m, ok := x.(*MakeExpr); ok && m.Size.IsConst() { + if sz, ok := m.Size.(Number); ok && sz.IsOne() { + return &NewExpr{ + e: g.env.Env, + Elem: m.Elem, + } + } + } return g.cAddr(g.NewCIndexExpr(x, cUintLit(0), nil)) } return &TakeAddr{g: g, X: x}