How to use canBeArgRet method of compiler Package

Best Syzkaller code snippet using compiler.canBeArgRet

types.go

Source:types.go Github

copy

Full Screen

...49 kindIdent50 kindString51)52func canBeArg(comp *compiler, t *ast.Type) (bool, bool) { return true, false }53func canBeArgRet(comp *compiler, t *ast.Type) (bool, bool) { return true, true }54var typeInt = &typeDesc{55 Names: typeArgBase.Type.Names,56 CanBeArgRet: canBeArg,57 CanBeTypedef: true,58 AllowColon: true,59 ResourceBase: true,60 OptArgs: 1,61 Args: []namedArg{{"range", typeArgRange}},62 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {63 typeArgBase.Type.Check(comp, t)64 },65 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {66 size, be := comp.parseIntType(t.Ident)67 kind, rangeBegin, rangeEnd := prog.IntPlain, uint64(0), uint64(0)68 if len(args) > 0 {69 kind, rangeBegin, rangeEnd = prog.IntRange, args[0].Value, args[0].Value270 }71 base.TypeSize = size72 return &prog.IntType{73 IntTypeCommon: genIntCommon(base.TypeCommon, t.Value2, be),74 Kind: kind,75 RangeBegin: rangeBegin,76 RangeEnd: rangeEnd,77 }78 },79}80var typePtr = &typeDesc{81 Names: []string{"ptr", "ptr64"},82 CanBeArgRet: canBeArg,83 CanBeTypedef: true,84 Args: []namedArg{{"direction", typeArgDir}, {"type", typeArgType}},85 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {86 base.ArgDir = prog.DirIn // pointers are always in87 base.TypeSize = comp.ptrSize88 if t.Ident == "ptr64" {89 base.TypeSize = 890 }91 return &prog.PtrType{92 TypeCommon: base.TypeCommon,93 Type: comp.genType(args[1], "", genDir(args[0]), false),94 }95 },96}97var typeVoid = &typeDesc{98 Names: []string{"void"},99 CantBeOpt: true,100 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {101 return true102 },103 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {104 base.TypeSize = 0 // the only type with static size 0105 return &prog.BufferType{106 TypeCommon: base.TypeCommon,107 Kind: prog.BufferBlobRange,108 RangeBegin: 0,109 RangeEnd: 0,110 }111 },112}113var typeArray = &typeDesc{114 Names: []string{"array"},115 CanBeTypedef: true,116 CantBeOpt: true,117 OptArgs: 1,118 Args: []namedArg{{"type", typeArgType}, {"size", typeArgRange}},119 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {120 if len(args) > 1 && args[1].Value == 0 && args[1].Value2 == 0 {121 comp.error(args[1].Pos, "arrays of size 0 are not supported")122 }123 },124 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {125 if comp.isZeroSize(args[0]) {126 return false127 }128 if comp.isVarlen(args[0]) {129 return true130 }131 if len(args) > 1 {132 return args[1].Value != args[1].Value2133 }134 return true135 },136 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {137 return comp.isZeroSize(args[0])138 },139 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {140 elemType := comp.genType(args[0], "", base.ArgDir, false)141 kind, begin, end := prog.ArrayRandLen, uint64(0), uint64(0)142 if len(args) > 1 {143 kind, begin, end = prog.ArrayRangeLen, args[1].Value, args[1].Value2144 }145 if it, ok := elemType.(*prog.IntType); ok && it.Kind == prog.IntPlain && it.TypeSize == 1 {146 // Special case: buffer is better mutated.147 bufKind := prog.BufferBlobRand148 base.TypeSize = 0149 if kind == prog.ArrayRangeLen {150 bufKind = prog.BufferBlobRange151 if begin == end {152 base.TypeSize = begin * elemType.Size()153 }154 }155 return &prog.BufferType{156 TypeCommon: base.TypeCommon,157 Kind: bufKind,158 RangeBegin: begin,159 RangeEnd: end,160 }161 }162 // TypeSize is assigned later in genStructDescs.163 return &prog.ArrayType{164 TypeCommon: base.TypeCommon,165 Type: elemType,166 Kind: kind,167 RangeBegin: begin,168 RangeEnd: end,169 }170 },171}172var typeLen = &typeDesc{173 Names: []string{"len", "bytesize", "bytesize2", "bytesize4", "bytesize8", "bitsize"},174 CanBeArgRet: canBeArg,175 CantBeOpt: true,176 NeedBase: true,177 Args: []namedArg{{"len target", typeArgLenTarget}},178 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {179 var bitSize uint64180 switch t.Ident {181 case "bytesize":182 bitSize = 8183 case "bytesize2", "bytesize4", "bytesize8":184 byteSize, _ := strconv.ParseUint(t.Ident[8:], 10, 8)185 bitSize = byteSize * 8186 case "bitsize":187 bitSize = 1188 }189 return &prog.LenType{190 IntTypeCommon: base,191 Buf: args[0].Ident,192 BitSize: bitSize,193 }194 },195}196var typeConst = &typeDesc{197 Names: []string{"const"},198 CanBeArgRet: canBeArg,199 CanBeTypedef: true,200 CantBeOpt: true,201 NeedBase: true,202 Args: []namedArg{{"value", typeArgInt}},203 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {204 return &prog.ConstType{205 IntTypeCommon: base,206 Val: args[0].Value,207 }208 },209}210var typeArgLenTarget = &typeArg{211 Kind: kindIdent,212}213var typeFlags = &typeDesc{214 Names: []string{"flags"},215 CanBeArgRet: canBeArg,216 CanBeTypedef: true,217 CantBeOpt: true,218 NeedBase: true,219 Args: []namedArg{{"flags", typeArgFlags}},220 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {221 name := args[0].Ident222 base.TypeName = name223 f := comp.intFlags[name]224 if len(f.Values) == 0 {225 // We can get this if all values are unsupported consts.226 return &prog.IntType{227 IntTypeCommon: base,228 Kind: prog.IntPlain,229 }230 }231 return &prog.FlagsType{232 IntTypeCommon: base,233 Vals: genIntArray(f.Values),234 }235 },236}237var typeArgFlags = &typeArg{238 Kind: kindIdent,239 Check: func(comp *compiler, t *ast.Type) {240 if comp.intFlags[t.Ident] == nil {241 comp.error(t.Pos, "unknown flags %v", t.Ident)242 return243 }244 },245}246var typeFileoff = &typeDesc{247 Names: []string{"fileoff"},248 CanBeArgRet: canBeArg,249 CantBeOpt: true,250 NeedBase: true,251 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {252 return &prog.IntType{253 IntTypeCommon: base,254 Kind: prog.IntFileoff,255 }256 },257}258var typeVMA = &typeDesc{259 Names: []string{"vma"},260 CanBeArgRet: canBeArg,261 OptArgs: 1,262 Args: []namedArg{{"size range", typeArgRange}},263 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {264 begin, end := uint64(0), uint64(0)265 if len(args) > 0 {266 begin, end = args[0].Value, args[0].Value2267 }268 base.TypeSize = comp.ptrSize269 return &prog.VmaType{270 TypeCommon: base.TypeCommon,271 RangeBegin: begin,272 RangeEnd: end,273 }274 },275}276var typeCsum = &typeDesc{277 Names: []string{"csum"},278 NeedBase: true,279 CantBeOpt: true,280 OptArgs: 1,281 Args: []namedArg{{"csum target", typeArgLenTarget}, {"kind", typeArgCsumType}, {"proto", typeArgInt}},282 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {283 if len(args) > 2 && genCsumKind(args[1]) != prog.CsumPseudo {284 comp.error(args[2].Pos, "only pseudo csum can have proto")285 }286 },287 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {288 var proto uint64289 if len(args) > 2 {290 proto = args[2].Value291 }292 return &prog.CsumType{293 IntTypeCommon: base,294 Buf: args[0].Ident,295 Kind: genCsumKind(args[1]),296 Protocol: proto,297 }298 },299}300var typeArgCsumType = &typeArg{301 Kind: kindIdent,302 Names: []string{"inet", "pseudo"},303}304func genCsumKind(t *ast.Type) prog.CsumKind {305 switch t.Ident {306 case "inet":307 return prog.CsumInet308 case "pseudo":309 return prog.CsumPseudo310 default:311 panic(fmt.Sprintf("unknown csum kind %q", t.Ident))312 }313}314var typeProc = &typeDesc{315 Names: []string{"proc"},316 CanBeArgRet: canBeArg,317 CanBeTypedef: true,318 NeedBase: true,319 Args: []namedArg{{"range start", typeArgInt}, {"per-proc values", typeArgInt}},320 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {321 start := args[0].Value322 perProc := args[1].Value323 if perProc == 0 {324 comp.error(args[1].Pos, "proc per-process values must not be 0")325 return326 }327 size := base.TypeSize * 8328 if size != 64 {329 const maxPids = 32 // executor knows about this constant (MAX_PIDS)330 if start >= 1<<size {331 comp.error(args[0].Pos, "values starting from %v overflow base type", start)332 } else if start+maxPids*perProc > 1<<size {333 comp.error(args[0].Pos, "values starting from %v with step %v overflow base type for %v procs",334 start, perProc, maxPids)335 }336 }337 },338 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {339 return &prog.ProcType{340 IntTypeCommon: base,341 ValuesStart: args[0].Value,342 ValuesPerProc: args[1].Value,343 }344 },345}346var typeText = &typeDesc{347 Names: []string{"text"},348 CantBeOpt: true,349 Args: []namedArg{{"kind", typeArgTextType}},350 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {351 return true352 },353 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {354 base.TypeSize = 0355 return &prog.BufferType{356 TypeCommon: base.TypeCommon,357 Kind: prog.BufferText,358 Text: genTextType(args[0]),359 }360 },361}362var typeArgTextType = &typeArg{363 Kind: kindIdent,364 Names: []string{"x86_real", "x86_16", "x86_32", "x86_64", "arm64"},365}366func genTextType(t *ast.Type) prog.TextKind {367 switch t.Ident {368 case "x86_real":369 return prog.TextX86Real370 case "x86_16":371 return prog.TextX86bit16372 case "x86_32":373 return prog.TextX86bit32374 case "x86_64":375 return prog.TextX86bit64376 case "arm64":377 return prog.TextArm64378 default:379 panic(fmt.Sprintf("unknown text type %q", t.Ident))380 }381}382var typeBuffer = &typeDesc{383 Names: []string{"buffer"},384 CanBeArgRet: canBeArg,385 Args: []namedArg{{"direction", typeArgDir}},386 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {387 base.TypeSize = comp.ptrSize388 common := genCommon("", "", 0, genDir(args[0]), false)389 // BufferBlobRand is always varlen.390 common.IsVarlen = true391 return &prog.PtrType{392 TypeCommon: base.TypeCommon,393 Type: &prog.BufferType{394 TypeCommon: common,395 Kind: prog.BufferBlobRand,396 },397 }398 },399}400const (401 stringnoz = "stringnoz"402)403var typeString = &typeDesc{404 Names: []string{"string", stringnoz},405 CanBeTypedef: true,406 OptArgs: 2,407 Args: []namedArg{{"literal or flags", typeArgStringFlags}, {"size", typeArgInt}},408 Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {409 if t.Ident == stringnoz && len(args) > 1 {410 comp.error(args[0].Pos, "fixed-size string can't be non-zero-terminated")411 }412 },413 CheckConsts: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) {414 if len(args) > 1 {415 size := args[1].Value416 vals := comp.genStrings(t, args)417 for _, s := range vals {418 if uint64(len(s)) > size {419 comp.error(args[0].Pos, "string value %q exceeds buffer length %v",420 s, size)421 }422 }423 }424 },425 Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {426 return comp.stringSize(t, args) == varlenString427 },428 ZeroSize: func(comp *compiler, t *ast.Type, args []*ast.Type) bool {429 return comp.stringSize(t, args) == 0430 },431 Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {432 if len(args) > 0 && args[0].Ident == "filename" {433 base.TypeName = "filename"434 base.TypeSize = 0435 if len(args) >= 2 {436 base.TypeSize = args[1].Value437 }438 return &prog.BufferType{439 TypeCommon: base.TypeCommon,440 Kind: prog.BufferFilename,441 NoZ: t.Ident == stringnoz,442 }443 }444 subkind := ""445 if len(args) > 0 && args[0].Ident != "" {446 subkind = args[0].Ident447 }448 vals := comp.genStrings(t, args)449 base.TypeSize = comp.stringSize(t, args)450 if base.TypeSize == varlenString {451 base.TypeSize = 0452 }453 return &prog.BufferType{454 TypeCommon: base.TypeCommon,455 Kind: prog.BufferString,456 SubKind: subkind,457 Values: vals,458 NoZ: t.Ident == stringnoz,459 }460 },461}462func (comp *compiler) genStrings(t *ast.Type, args []*ast.Type) []string {463 var vals []string464 if len(args) > 0 {465 if args[0].HasString {466 vals = append(vals, args[0].String)467 } else {468 vals = genStrArray(comp.strFlags[args[0].Ident].Values)469 }470 }471 if t.Ident == stringnoz {472 return vals473 }474 var size uint64475 if len(args) > 1 {476 size = args[1].Value477 }478 for i, s := range vals {479 s += "\x00"480 for uint64(len(s)) < size {481 s += "\x00"482 }483 vals[i] = s484 }485 return vals486}487const varlenString = ^uint64(0)488// stringSize returns static string size, or varlenString if it is variable length.489func (comp *compiler) stringSize(t *ast.Type, args []*ast.Type) uint64 {490 switch len(args) {491 case 0:492 return varlenString // a random string493 case 1:494 var z uint64495 if t.Ident == "string" {496 z = 1497 }498 if args[0].HasString {499 return uint64(len(args[0].String)) + z // string constant500 }501 size := varlenString502 for _, s := range comp.strFlags[args[0].Ident].Values {503 s1 := uint64(len(s.Value)) + z504 if size != varlenString && size != s1 {505 return varlenString // strings of different lengths506 }507 size = s1508 }509 return size // all strings have the same length510 case 2:511 return args[1].Value // have explicit length512 default:513 panic("too many string args")514 }515}516var typeArgStringFlags = &typeArg{517 Check: func(comp *compiler, t *ast.Type) {518 if !t.HasString && t.Ident == "" {519 comp.error(t.Pos, "unexpected int %v, string arg must be a string literal or string flags", t.Value)520 return521 }522 if t.Ident != "" && comp.strFlags[t.Ident] == nil {523 comp.error(t.Pos, "unknown string flags %v", t.Ident)524 return525 }526 },527}528// typeArgType is used as placeholder for any type (e.g. ptr target type).529var typeArgType = &typeArg{}530var typeResource = &typeDesc{531 // No Names, but getTypeDesc knows how to match it.532 CanBeArgRet: canBeArgRet,533 ResourceBase: true,534 // Gen is assigned below to avoid initialization loop.535}536func init() {537 typeResource.Gen = func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type {538 // Find and generate base type to get its size.539 var baseType *ast.Type540 for r := comp.resources[t.Ident]; r != nil; {541 baseType = r.Base542 r = comp.resources[r.Base.Ident]543 }544 base.TypeSize = comp.genType(baseType, "", prog.DirIn, false).Size()545 return &prog.ResourceType{546 TypeCommon: base.TypeCommon,...

Full Screen

Full Screen

canBeArgRet

Using AI Code Generation

copy

Full Screen

1import (2type compiler struct {3}4func (c *compiler) canBeArgRet(n ast.Node) bool {5 _, ok := c.info.Types[n].Type.(*types.Basic)6}7func main() {8 fset := token.NewFileSet()9 f, err := parser.ParseFile(fset, "2.go", nil, parser.ParseComments)10 if err != nil {11 panic(err)12 }13 conf := types.Config{Importer: types.DefaultImporter()}14 info := &types.Info{15 Defs: make(map[*ast.Ident]types.Object),16 }17 _, err = conf.Check("main", fset, []*ast.File{f}, info)18 if err != nil {19 panic(err)20 }21 c := &compiler{22 }23 ast.Inspect(f, func(n ast.Node) bool {24 if n == nil {25 }26 if c.canBeArgRet(n) {27 fmt.Println("can be arg/ret", n)28 }29 })30}

Full Screen

Full Screen

canBeArgRet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 func main() {4 y = add(x, y)5 }6 func add(a, b int) int {7 }8 f, err := parser.ParseFile(fset, "", src, 0)9 if err != nil {10 fmt.Println(err)11 }12 ast.Print(fset, f)

Full Screen

Full Screen

canBeArgRet

Using AI Code Generation

copy

Full Screen

1import "fmt"2type compiler struct{}3func (c *compiler) canBeArgRet(t interface{}) bool {4 switch t.(type) {5 }6}7func main() {8 c := &compiler{}9 fmt.Println(c.canBeArgRet("hello"))10 fmt.Println(c.canBeArgRet(1))11 fmt.Println(c.canBeArgRet(1.0))12 fmt.Println(c.canBeArgRet(1.0i))13 fmt.Println(c.canBeArgRet([]string{"hello"}))14}

Full Screen

Full Screen

canBeArgRet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(c.CanBeArgRet(1))4 fmt.Println(c.CanBeArgRet(2))5 fmt.Println(c.CanBeArgRet(3))6 fmt.Println(c.CanBeArgRet(4))7 fmt.Println(c.CanBeArgRet(5))8 fmt.Println(c.CanBeArgRet(6))9 fmt.Println(c.CanBeArgRet(7))10 fmt.Println(c.CanBeArgRet(8))11 fmt.Println(c.CanBeArgRet(9))12 fmt.Println(c.CanBeArgRet(10))13 fmt.Println(c.CanBeArgRet(11))14 fmt.Println(c.CanBeArgRet(12))15 fmt.Println(c.CanBeArgRet(13))16 fmt.Println(c.CanBeArgRet(14))17 fmt.Println(c.CanBeArgRet(15))18 fmt.Println(c.CanBeArgRet(16))19 fmt.Println(c.CanBeArgRet(17))20 fmt.Println(c.CanBeArgRet(18))21 fmt.Println(c.CanBeArgRet(19))22 fmt.Println(c.CanBeArgRet(20))23 fmt.Println(c.CanBeArgRet(21))24 fmt.Println(c.CanBeArgRet(22))25 fmt.Println(c.CanBeArgRet(23))26 fmt.Println(c.CanBeArgRet(24))27 fmt.Println(c.CanBeArgRet(25))28 fmt.Println(c.CanBeArgRet(26))29 fmt.Println(c.CanBeArgRet(27))30 fmt.Println(c.CanBeArgRet(28))31 fmt.Println(c.CanBeArgRet(29))32 fmt.Println(c.CanBeArgRet(30))33 fmt.Println(c.CanBeArgRet(31))34 fmt.Println(c.CanBeArgRet(32))35 fmt.Println(c.CanBeArgRet(33))36 fmt.Println(c.CanBeArgRet(34))37 fmt.Println(c.CanBeArgRet(35))38 fmt.Println(c.CanBeArgRet(36))39 fmt.Println(c.CanBeArgRet(37))40 fmt.Println(c.CanBeArgRet(38))41 fmt.Println(c.CanBeArgRet(39))42 fmt.Println(c.CanBeArgRet(40))43 fmt.Println(c.CanBeArgRet(41))44 fmt.Println(c.CanBeArgRet(42))45 fmt.Println(c.CanBeArgRet(43))46 fmt.Println(c.CanBeArgRet(44))

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful