go/loader: don't create types.Package for "unsafe"

https://golang.org/cl/37694 is a backwards-incompatible change to the
go/types API that causes "unsafe" to be included among the results of
(*types.Package).Imports().  Client packages such as go/loader and
go/ssa now need to recognize the special unsafe package and its
unusual *Bultin members and not create a types.Package for it.

Change-Id: I902725d3053cb887246978efdb5ec5dcdc0e4818
Reviewed-on: https://go-review.googlesource.com/37710
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/go/loader/loader.go b/go/loader/loader.go
index f03e8f9..f69a668 100644
--- a/go/loader/loader.go
+++ b/go/loader/loader.go
@@ -1009,6 +1009,10 @@
 			time.Since(imp.start), info.Pkg.Path(), len(files))
 	}
 
+	if info.Pkg == types.Unsafe && len(files) > 0 {
+		panic(`addFiles("unsafe") not permitted`)
+	}
+
 	// Ignore the returned (first) error since we
 	// already collect them all in the PackageInfo.
 	info.checker.Files(files)
@@ -1025,7 +1029,12 @@
 }
 
 func (imp *importer) newPackageInfo(path, dir string) *PackageInfo {
-	pkg := types.NewPackage(path, "")
+	var pkg *types.Package
+	if path == "unsafe" {
+		pkg = types.Unsafe
+	} else {
+		pkg = types.NewPackage(path, "")
+	}
 	info := &PackageInfo{
 		Pkg: pkg,
 		Info: types.Info{