<commit_before>package gotypes

import (
	"bytes"
	"fmt"
	"go/ast"
	"go/format"
	"go/parser"
	"go/token"
	"io/ioutil"
	"os"
	"os/exec"
	"regexp"
	"strings"

	_ "golang.org/x/tools/go/gcimporter"
	"golang.org/x/tools/go/ssa"
	"golang.org/x/tools/go/types"
)

// https://github.com/golang/go/issues/11327
var bigNum = regexp.MustCompile("(\\.[0-9]*)|([0-9]+)[eE]\\-?[0-9]{3,}")

// https://github.com/golang/go/issues/11274
var formatBug1 = regexp.MustCompile("\\*/[ \t\n\r\f\v]*;")
var formatBug2 = regexp.MustCompile(";[ \t\n\r\f\v]*/\\*")

var gcCrash = regexp.MustCompile("\n/tmp/fuzz\\.gc[0-9]+:[0-9]+: internal compiler error: ")

func Fuzz(data []byte) int {
	if bigNum.Match(data) {
		return 0
	}
	goErr := gotypes(data)
	gcErr := gc(data)
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "line number out of range") {
		// https://github.com/golang/go/issues/11329
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "stupid shift:") {
		// https://github.com/golang/go/issues/11328
		return 0
	}
	if gcErr == nil && goErr != nil && strings.Contains(goErr.Error(), "untyped float constant") {
		// https://github.com/golang/go/issues/11350
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "(type float64) to type string") {
		// https://github.com/golang/go/issues/11353
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "(type complex128) to type string") {
		// https://github.com/golang/go/issues/11357
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "overflow in int -> string") {
		// https://github.com/golang/go/issues/11330
		return 0
	}
	if gcErr == nil && goErr != nil && strings.Contains(goErr.Error(), "illegal character U+") {
		// https://github.com/golang/go/issues/11359
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "larger than address space") {
		// Gc is more picky at rejecting huge objects.
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "non-canonical import path") {
		return 0
	}
	// go-fuzz is too smart so it can generate a program that contains "internal compiler error" in an error message :)
	if gcErr != nil && gcCrash.MatchString(gcErr.Error()) {
		if strings.Contains(gcErr.Error(), "internal compiler error: out of fixed registers") {
			// https://github.com/golang/go/issues/11352
			return 0
		}
		if strings.Contains(gcErr.Error(), "internal compiler error: naddr: bad HMUL") {
			// https://github.com/golang/go/issues/11358
			return 0<commit_msg>remove fixed bugs from gotypes test<commit_after>package gotypes

import (
	"bytes"
	"fmt"
	"go/ast"
	"go/format"
	"go/parser"
	"go/token"
	"io/ioutil"
	"os"
	"os/exec"
	"regexp"
	"strings"

	_ "golang.org/x/tools/go/gcimporter"
	"golang.org/x/tools/go/ssa"
	"golang.org/x/tools/go/types"
)

// https://github.com/golang/go/issues/11327
var bigNum = regexp.MustCompile("(\\.[0-9]*)|([0-9]+)[eE]\\-?[0-9]{3,}")

// https://github.com/golang/go/issues/11274
var formatBug1 = regexp.MustCompile("\\*/[ \t\n\r\f\v]*;")
var formatBug2 = regexp.MustCompile(";[ \t\n\r\f\v]*/\\*")

var gcCrash = regexp.MustCompile("\n/tmp/fuzz\\.gc[0-9]+:[0-9]+: internal compiler error: ")

func Fuzz(data []byte) int {
	if bigNum.Match(data) {
		return 0
	}
	goErr := gotypes(data)
	gcErr := gc(data)
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "line number out of range") {
		// https://github.com/golang/go/issues/11329
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "stupid shift:") {
		// https://github.com/golang/go/issues/11328
		return 0
	}
	if gcErr == nil && goErr != nil && strings.Contains(goErr.Error(), "untyped float constant") {
		// https://github.com/golang/go/issues/11350
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "overflow in int -> string") {
		// https://github.com/golang/go/issues/11330
		return 0
	}
	if gcErr == nil && goErr != nil && strings.Contains(goErr.Error(), "illegal character U+") {
		// https://github.com/golang/go/issues/11359
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "larger than address space") {
		// Gc is more picky at rejecting huge objects.
		return 0
	}
	if goErr == nil && gcErr != nil && strings.Contains(gcErr.Error(), "non-canonical import path") {
		return 0
	}
	// go-fuzz is too smart so it can generate a program that contains "internal compiler error" in an error message :)
	if gcErr != nil && gcCrash.MatchString(gcErr.Error()) {
		if strings.Contains(gcErr.Error(), "internal compiler error: out of fixed registers") {
			// https://github.com/golang/go/issues/11352
			return 0
{'fraction_non_alphanumeric': 0.19266247379454926, 'fraction_numerical': 0.030817610062893082, 'mean_word_length': 3.438139534883721, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 19, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004376', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1800, 'n_words': 395}