diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-05-16 18:05:05 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-05-16 18:05:05 +0200 |
| commit | 76fc461b55cfe334e8d4be121f61fa25d079f8ba (patch) | |
| tree | 88cc3472e7352c2cd74f3234acb4bd2083ff61d4 /pkg/compiler/check.go | |
| parent | f59a9cb554a8dfcbe13c8a0775542ee7a0d8a353 (diff) | |
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.
Diffstat (limited to 'pkg/compiler/check.go')
| -rw-r--r-- | pkg/compiler/check.go | 7 |
1 files changed, 6 insertions, 1 deletions
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) |
