Best Syzkaller code snippet using compiler.checkRecursion
check.go
Source:check.go
...18 if comp.errors != 0 {19 return20 }21 comp.checkUsed()22 comp.checkRecursion()23 comp.checkLenTargets()24 comp.checkConstructors()25 comp.checkVarlens()26}27func (comp *compiler) checkNames() {28 calls := make(map[string]*ast.Call)29 for _, decl := range comp.desc.Nodes {30 switch decl.(type) {31 case *ast.Resource, *ast.Struct:32 pos, typ, name := decl.Info()33 if reservedName[name] {34 comp.error(pos, "%v uses reserved name %v", typ, name)35 continue36 }37 if builtinTypes[name] != nil {38 comp.error(pos, "%v name %v conflicts with builtin type", typ, name)39 continue40 }41 if prev := comp.resources[name]; prev != nil {42 comp.error(pos, "type %v redeclared, previously declared as resource at %v",43 name, prev.Pos)44 continue45 }46 if prev := comp.structs[name]; prev != nil {47 _, typ, _ := prev.Info()48 comp.error(pos, "type %v redeclared, previously declared as %v at %v",49 name, typ, prev.Pos)50 continue51 }52 if res, ok := decl.(*ast.Resource); ok {53 comp.resources[name] = res54 } else if str, ok := decl.(*ast.Struct); ok {55 comp.structs[name] = str56 }57 case *ast.IntFlags:58 n := decl.(*ast.IntFlags)59 name := n.Name.Name60 if reservedName[name] {61 comp.error(n.Pos, "flags uses reserved name %v", name)62 continue63 }64 if prev := comp.intFlags[name]; prev != nil {65 comp.error(n.Pos, "flags %v redeclared, previously declared at %v",66 name, prev.Pos)67 continue68 }69 comp.intFlags[name] = n70 case *ast.StrFlags:71 n := decl.(*ast.StrFlags)72 name := n.Name.Name73 if reservedName[name] {74 comp.error(n.Pos, "string flags uses reserved name %v", name)75 continue76 }77 if prev := comp.strFlags[name]; prev != nil {78 comp.error(n.Pos, "string flags %v redeclared, previously declared at %v",79 name, prev.Pos)80 continue81 }82 comp.strFlags[name] = n83 case *ast.Call:84 c := decl.(*ast.Call)85 name := c.Name.Name86 if prev := calls[name]; prev != nil {87 comp.error(c.Pos, "syscall %v redeclared, previously declared at %v",88 name, prev.Pos)89 }90 calls[name] = c91 }92 }93}94func (comp *compiler) checkFields() {95 const maxArgs = 9 // executor does not support more96 for _, decl := range comp.desc.Nodes {97 switch n := decl.(type) {98 case *ast.Struct:99 _, typ, name := n.Info()100 fields := make(map[string]bool)101 for _, f := range n.Fields {102 fn := f.Name.Name103 if fn == "parent" {104 comp.error(f.Pos, "reserved field name %v in %v %v", fn, typ, name)105 }106 if fields[fn] {107 comp.error(f.Pos, "duplicate field %v in %v %v", fn, typ, name)108 }109 fields[fn] = true110 }111 if !n.IsUnion && len(n.Fields) < 1 {112 comp.error(n.Pos, "struct %v has no fields, need at least 1 field", name)113 }114 if n.IsUnion && len(n.Fields) < 2 {115 comp.error(n.Pos, "union %v has only %v field, need at least 2 fields",116 name, len(n.Fields))117 }118 case *ast.Call:119 name := n.Name.Name120 args := make(map[string]bool)121 for _, a := range n.Args {122 an := a.Name.Name123 if an == "parent" {124 comp.error(a.Pos, "reserved argument name %v in syscall %v",125 an, name)126 }127 if args[an] {128 comp.error(a.Pos, "duplicate argument %v in syscall %v",129 an, name)130 }131 args[an] = true132 }133 if len(n.Args) > maxArgs {134 comp.error(n.Pos, "syscall %v has %v arguments, allowed maximum is %v",135 name, len(n.Args), maxArgs)136 }137 }138 }139}140func (comp *compiler) checkTypes() {141 for _, decl := range comp.desc.Nodes {142 switch n := decl.(type) {143 case *ast.Resource:144 comp.checkType(n.Base, false, false, false, true)145 case *ast.Struct:146 for _, f := range n.Fields {147 comp.checkType(f.Type, false, false, !n.IsUnion, false)148 }149 comp.checkStruct(n)150 case *ast.Call:151 for _, a := range n.Args {152 comp.checkType(a.Type, true, false, false, false)153 }154 if n.Ret != nil {155 comp.checkType(n.Ret, true, true, false, false)156 }157 }158 }159}160func (comp *compiler) checkLenTargets() {161 for _, decl := range comp.desc.Nodes {162 switch n := decl.(type) {163 case *ast.Call:164 for _, arg := range n.Args {165 comp.checkLenType(arg.Type, arg.Name.Name, n.Args, nil, make(map[string]bool), true)166 }167 }168 }169}170func (comp *compiler) checkLenType(t *ast.Type, name string, fields []*ast.Field,171 parents []*ast.Struct, checked map[string]bool, isArg bool) {172 desc := comp.getTypeDesc(t)173 if desc == typeStruct {174 s := comp.structs[t.Ident]175 // Prune recursion, can happen even on correct tree via opt pointers.176 if checked[s.Name.Name] {177 return178 }179 checked[s.Name.Name] = true180 parents = append(parents, s)181 for _, fld := range s.Fields {182 comp.checkLenType(fld.Type, fld.Name.Name, s.Fields, parents, checked, false)183 }184 return185 }186 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)187 for i, arg := range args {188 argDesc := desc.Args[i]189 if argDesc.Type == typeArgLenTarget {190 comp.checkLenTarget(t, name, arg.Ident, fields, parents)191 } else if argDesc.Type == typeArgType {192 comp.checkLenType(arg, name, fields, parents, checked, false)193 }194 }195}196func (comp *compiler) checkLenTarget(t *ast.Type, name, target string, fields []*ast.Field, parents []*ast.Struct) {197 if target == name {198 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)199 return200 }201 if target == "parent" {202 if len(parents) == 0 {203 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)204 }205 return206 }207 for _, fld := range fields {208 if target != fld.Name.Name {209 continue210 }211 if fld.Type == t {212 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)213 }214 return215 }216 for _, parent := range parents {217 if target == parent.Name.Name {218 return219 }220 }221 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)222}223func (comp *compiler) checkUsed() {224 for _, decl := range comp.desc.Nodes {225 switch n := decl.(type) {226 case *ast.Call:227 if n.NR == ^uint64(0) {228 break229 }230 for _, arg := range n.Args {231 comp.checkUsedType(arg.Type, true)232 }233 if n.Ret != nil {234 comp.checkUsedType(n.Ret, true)235 }236 }237 }238}239func (comp *compiler) checkUsedType(t *ast.Type, isArg bool) {240 if comp.used[t.Ident] {241 return242 }243 desc := comp.getTypeDesc(t)244 if desc == typeResource {245 r := comp.resources[t.Ident]246 for r != nil && !comp.used[r.Name.Name] {247 comp.used[r.Name.Name] = true248 r = comp.resources[r.Base.Ident]249 }250 return251 }252 if desc == typeStruct {253 comp.used[t.Ident] = true254 s := comp.structs[t.Ident]255 for _, fld := range s.Fields {256 comp.checkUsedType(fld.Type, false)257 }258 return259 }260 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)261 for i, arg := range args {262 if desc.Args[i].Type == typeArgType {263 comp.checkUsedType(arg, false)264 }265 }266}267type structDir struct {268 Struct string269 Dir prog.Dir270}271func (comp *compiler) checkConstructors() {272 ctors := make(map[string]bool) // resources for which we have ctors273 checked := make(map[structDir]bool)274 for _, decl := range comp.desc.Nodes {275 switch n := decl.(type) {276 case *ast.Call:277 for _, arg := range n.Args {278 comp.checkTypeCtors(arg.Type, prog.DirIn, true, ctors, checked)279 }280 if n.Ret != nil {281 comp.checkTypeCtors(n.Ret, prog.DirOut, true, ctors, checked)282 }283 }284 }285 for _, decl := range comp.desc.Nodes {286 switch n := decl.(type) {287 case *ast.Resource:288 name := n.Name.Name289 if !ctors[name] && comp.used[name] {290 comp.error(n.Pos, "resource %v can't be created"+291 " (never mentioned as a syscall return value or output argument/field)",292 name)293 }294 }295 }296}297func (comp *compiler) checkTypeCtors(t *ast.Type, dir prog.Dir, isArg bool,298 ctors map[string]bool, checked map[structDir]bool) {299 desc := comp.getTypeDesc(t)300 if desc == typeResource {301 // TODO(dvyukov): consider changing this to "dir == prog.DirOut".302 // We have few questionable cases where resources can be created303 // only by inout struct fields. These structs should be split304 // into two different structs: one is in and second is out.305 // But that will require attaching dir to individual fields.306 if dir != prog.DirIn {307 r := comp.resources[t.Ident]308 for r != nil && !ctors[r.Name.Name] {309 ctors[r.Name.Name] = true310 r = comp.resources[r.Base.Ident]311 }312 }313 return314 }315 if desc == typeStruct {316 s := comp.structs[t.Ident]317 name := s.Name.Name318 key := structDir{name, dir}319 if checked[key] {320 return321 }322 checked[key] = true323 for _, fld := range s.Fields {324 comp.checkTypeCtors(fld.Type, dir, false, ctors, checked)325 }326 return327 }328 if desc == typePtr {329 dir = genDir(t.Args[0])330 }331 _, args, _ := comp.getArgsBase(t, "", dir, isArg)332 for i, arg := range args {333 if desc.Args[i].Type == typeArgType {334 comp.checkTypeCtors(arg, dir, false, ctors, checked)335 }336 }337}338func (comp *compiler) checkRecursion() {339 checked := make(map[string]bool)340 for _, decl := range comp.desc.Nodes {341 switch n := decl.(type) {342 case *ast.Resource:343 comp.checkResourceRecursion(n)344 case *ast.Struct:345 var path []pathElem346 comp.checkStructRecursion(checked, n, path)347 }348 }349}350func (comp *compiler) checkResourceRecursion(n *ast.Resource) {351 var seen []string352 for n != nil {...
checkRecursion
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println(c)4}5import "fmt"6func main() {7 fmt.Println(c)8}9import "fmt"10func main() {11 fmt.Println(c)12}13import "fmt"14func main() {15 fmt.Println(c)16}17import "fmt"18func main() {19 fmt.Println(c)20}21import "fmt"22func main() {23 fmt.Println(c)24}25import "fmt"26func main() {27 fmt.Println(c)28}29import "fmt"30func main() {31 fmt.Println(c)32}
checkRecursion
Using AI Code Generation
1import (2func main() {3 fmt.Println("Enter the string to be checked for recursion: ")4 fmt.Scanf("%s", &str)5 str=strings.ToUpper(str)6 fmt.Println("The string entered is: ", str)7 fmt.Println("Enter the string to be checked for recursion: ")8 fmt.Scanf("%s", &str1)9 str1=strings.ToUpper(str1)10 fmt.Println("The string entered is: ", str1)11 compiler.checkRecursion(str, str1)12}13import (14type compiler struct {15}16func (compiler) checkRecursion(str, str1 string) {17 if strings.Contains(str, str1) {18 fmt.Println("The string is recursive")19 } else {20 fmt.Println("The string is not recursive")21 }22}
checkRecursion
Using AI Code Generation
1{2 public static void main(String args[])3 {4 Compiler compiler = new Compiler();5 compiler.checkRecursion("2.txt");6 }7}8{9 public void checkRecursion(String filename)10 {11 {12 Scanner scanner = new Scanner(new File(filename));13 String line = scanner.nextLine();14 String[] array = line.split(" ");15 String input = array[0];16 String output = array[1];17 int count = 0;18 for(int i=0; i<output.length(); i++)19 {20 if(output.charAt(i) == input.charAt(0))21 {22 count++;23 }24 }25 if(count == output.length())26 {27 System.out.println("Recursion possible");28 }29 {30 System.out.println("Recursion not possible");31 }32 }33 catch(Exception e)34 {35 System.out.println("Exception: " + e);36 }37 }38}
checkRecursion
Using AI Code Generation
1import (2func main() {3 f, err := parser.ParseFile(fset, "1.go", nil, parser.AllErrors)4 if err != nil {5 }6 fmt.Println("Import declarations in", f.Name.Name)7 for _, s := range f.Decls {8 if genDecl, ok := s.(*ast.FuncDecl); ok {9 fmt.Println(genDecl.Name)10 fmt.Println(genDecl.Body)11 }12 }13}14import (15func main() {16 f, err := parser.ParseFile(fset, "1.go", nil, parser.AllErrors)17 if err != nil {18 }19 fmt.Println("Import declarations in", f.Name.Name)20 for _, s := range f.Decls {21 if genDecl, ok := s.(*ast.GenDecl); ok {22 fmt.Println(genDecl.Specs)23 }24 }25}
checkRecursion
Using AI Code Generation
1import (2func main() {3 compiler.checkRecursion(input)4}5type Compiler struct {6}7func (c Compiler) checkRecursion(input string) {8 if input == "" {9 fmt.Println("Input is empty")10 }11 if c.isRecursive(input) {12 fmt.Println("Input is recursive")13 } else {14 fmt.Println("Input is not recursive")15 }16}17func (c Compiler) isRecursive(input string) bool {18 if input == "" {19 }20 for _, ch := range input {21 if stack.isEmpty() {22 stack.push(ch)23 } else {24 if stack.top() == '(' && ch == ')' {25 stack.pop()26 } else {27 stack.push(ch)28 }29 }30 }31 return stack.isEmpty()32}33type Stack struct {34}35func (s Stack) push(ch rune) {36 stack = append(stack, ch)37}38func (s Stack) pop() {39 stack = stack[:len(stack)-1]40}41func (s Stack) top() rune {42 return stack[len(stack)-1]43}44func (s Stack) isEmpty() bool {45 return len(stack) == 046}
checkRecursion
Using AI Code Generation
1import (2const (3type Symbol struct {4}5type Production struct {6}7type Grammar struct {8}9type Compiler struct {10}11func NewCompiler(g Grammar) Compiler {12 return Compiler{Grammar: g}13}14func (c Compiler) IsNonTerminal(s Symbol) bool {15}16func (c Compiler) IsTerminal(s Symbol) bool {17}18func (c Compiler) IsEpsilon(s Symbol) bool {19}20func (c Compiler) IsEndOfInput(s Symbol) bool {21}22func (c Compiler) First(s Symbol) []Symbol {23 if c.IsNonTerminal(s) {24 for _, p := range c.Grammar.Productions {25 if p.Left == s {26 return c.First(p.Right[0])27 }28 }29 } else if c.IsTerminal(s) {30 return []Symbol{s}31 } else if c.IsEpsilon(s) {32 return []Symbol{s}33 } else {34 return []Symbol{}35 }36 return []Symbol{}37}38func (c Compiler) Follow(s Symbol) []Symbol {39 if c.IsNonTerminal(s) {40 for _, p := range c.Grammar.Productions {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!