return NewBasicLit(pos, types.UntypedString, constant.MakeString(s))
}
+// NewUintptr returns an OLITERAL representing v as a uintptr.
+func NewUintptr(pos src.XPos, v int64) Node {
+ return NewBasicLit(pos, types.Types[types.TUINTPTR], constant.MakeInt64(v))
+}
+
// NewOne returns an OLITERAL representing 1 with the given type.
func NewOne(pos src.XPos, typ *types.Type) Node {
var val constant.Value
exprConvert
exprNew
exprMake
+ exprSizeof
+ exprAlignof
+ exprOffsetof
exprNil
exprFuncInst
exprRecv
typ := r.exprType()
return typecheck.Expr(ir.NewUnaryExpr(pos, ir.ONEW, typ))
+ case exprSizeof:
+ return ir.NewUintptr(r.pos(), r.typ().Size())
+
+ case exprAlignof:
+ return ir.NewUintptr(r.pos(), r.typ().Alignment())
+
+ case exprOffsetof:
+ pos := r.pos()
+ typ := r.typ()
+ types.CalcSize(typ)
+
+ var offset int64
+ for i := r.Len(); i >= 0; i-- {
+ field := typ.Field(r.Len())
+ offset += field.Offset
+ typ = field.Type
+ }
+
+ return ir.NewUintptr(pos, offset)
+
case exprReshape:
typ := r.typ()
x := r.expr()
w.exprType(nil, expr.ArgList[0])
return
+ case "Sizeof":
+ assert(len(expr.ArgList) == 1)
+ assert(!expr.HasDots)
+
+ w.Code(exprSizeof)
+ w.pos(expr)
+ w.typ(w.p.typeOf(expr.ArgList[0]))
+ return
+
+ case "Alignof":
+ assert(len(expr.ArgList) == 1)
+ assert(!expr.HasDots)
+
+ w.Code(exprAlignof)
+ w.pos(expr)
+ w.typ(w.p.typeOf(expr.ArgList[0]))
+ return
+
+ case "Offsetof":
+ assert(len(expr.ArgList) == 1)
+ assert(!expr.HasDots)
+ selector := syntax.Unparen(expr.ArgList[0]).(*syntax.SelectorExpr)
+ index := w.p.info.Selections[selector].Index()
+
+ w.Code(exprOffsetof)
+ w.pos(expr)
+ w.typ(deref2(w.p.typeOf(selector.X)))
+ w.Len(len(index) - 1)
+ for _, idx := range index {
+ w.Len(idx)
+ }
+ return
+
case "append":
rtype = sliceElem(w.p.typeOf(expr))
case "copy":
--- /dev/null
+// compile
+
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Unified frontend generated unnecessary temporaries for expressions
+// within unsafe.Sizeof, etc functions.
+
+package main
+
+import "unsafe"
+
+func F[G int](g G) (uintptr, uintptr, uintptr) {
+ var c chan func() int
+ type s struct {
+ g G
+ x []int
+ }
+ return unsafe.Sizeof(s{g, make([]int, (<-c)())}),
+ unsafe.Alignof(s{g, make([]int, (<-c)())}),
+ unsafe.Offsetof(s{g, make([]int, (<-c)())}.x)
+}
+
+func main() {
+ F(0)
+}