Skip to content

Commit

Permalink
cxgo: properly unwrap new value when using calloc
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Mar 6, 2022
1 parent 669abaf commit a8be1f8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pointers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit a8be1f8

Please sign in to comment.