From 76fc461b55cfe334e8d4be121f61fa25d079f8ba Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 16 May 2019 18:05:05 +0200 Subject: pkg/compiler: add offsetof type Similar to C offsetof gives offset of a field from the beginning of the parent struct. We have several TODOs in descriptions asking for this. --- pkg/compiler/check.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pkg/compiler/check.go') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 0b296e2ea..24acfe50f 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -415,7 +415,12 @@ func (comp *compiler) checkLenTargetRec(t0, t *ast.Type, targets []*ast.Type, parent := parents[pi] if parent.name != "" && (parent.name == target.Ident || target.Ident == prog.ParentRef) || parent.name == "" && target.Ident == prog.SyscallRef { - if len(targets) != 0 { + if len(targets) == 0 { + if t.Ident == "offsetof" { + comp.error(target.Pos, "%v must refer to fields", t.Ident) + return + } + } else { parents1 := make([]parentDesc, pi+1) copy(parents1, parents[:pi+1]) comp.checkLenTargetRec(t0, t, targets, parents1, warned) -- cgit mrf-deployment