diff options
Diffstat (limited to 'src/cmd/gc')
-rw-r--r-- | src/cmd/gc/align.c | 3 | ||||
-rw-r--r-- | src/cmd/gc/go.y | 8 | ||||
-rw-r--r-- | src/cmd/gc/lex.c | 31 | ||||
-rw-r--r-- | src/cmd/gc/mparith3.c | 27 | ||||
-rw-r--r-- | src/cmd/gc/obj.c | 2 | ||||
-rw-r--r-- | src/cmd/gc/select.c | 4 | ||||
-rw-r--r-- | src/cmd/gc/subr.c | 3 | ||||
-rw-r--r-- | src/cmd/gc/typecheck.c | 5 |
8 files changed, 58 insertions, 25 deletions
diff --git a/src/cmd/gc/align.c b/src/cmd/gc/align.c index ed20e7e8b..833eba19a 100644 --- a/src/cmd/gc/align.c +++ b/src/cmd/gc/align.c @@ -54,7 +54,8 @@ widstruct(Type *t, uint32 o, int flag) if(f->type->width < 0) fatal("invalid width %lld", f->type->width); w = f->type->width; - o = rnd(o, f->type->align); + if(f->type->align > 0) + o = rnd(o, f->type->align); f->width = o; // really offset for TFIELD if(f->nname != N) { // this same stackparam logic is in addrescapes diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 994840ee8..86e3cae33 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -242,14 +242,6 @@ import_package: if(safemode && !curio.importsafe) yyerror("cannot import unsafe package %Z", importpkg->path); - - // NOTE(rsc): This is no longer a technical restriction: - // the 6g tool chain would work just fine without giving - // special meaning to a package being named main. - // Other implementations might need the restriction - // (gccgo does), so it stays in the language and the compiler. - if(strcmp($2->name, "main") == 0) - yyerror("cannot import package main"); } import_safety: diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index 45b1257fa..e79d3b0f8 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -405,7 +405,7 @@ void importfile(Val *f, int line) { Biobuf *imp; - char *file; + char *file, *p, *q; int32 c; int len; Strlit *path; @@ -423,6 +423,15 @@ importfile(Val *f, int line) errorexit(); } + // The package name main is no longer reserved, + // but we reserve the import path "main" to identify + // the main package, just as we reserve the import + // path "math" to identify the standard math package. + if(strcmp(f->u.sval->s, "main") == 0) { + yyerror("cannot import \"main\""); + errorexit(); + } + if(strcmp(f->u.sval->s, "unsafe") == 0) { if(safemode) { yyerror("cannot import package unsafe"); @@ -432,7 +441,7 @@ importfile(Val *f, int line) cannedimports("unsafe.6", unsafeimport); return; } - + path = f->u.sval; if(islocalname(path)) { cleanbuf = mal(strlen(pathname) + strlen(path->s) + 2); @@ -459,9 +468,24 @@ importfile(Val *f, int line) len = strlen(namebuf); if(len > 2 && namebuf[len-2] == '.' && namebuf[len-1] == 'a') { if(!skiptopkgdef(imp)) { - yyerror("import not package file: %s", namebuf); + yyerror("import %s: not a package file", file); + errorexit(); + } + } + + // check object header + p = Brdstr(imp, '\n', 1); + if(strcmp(p, "empty archive") != 0) { + if(strncmp(p, "go object ", 10) != 0) { + yyerror("import %s: not a go object file", file); errorexit(); } + q = smprint("%s %s %s", getgoos(), thestring, getgoversion()); + if(strcmp(p+10, q) != 0) { + yyerror("import %s: object is [%s] expected [%s]", file, p+10, q); + errorexit(); + } + free(q); } // assume files move (get installed) @@ -479,6 +503,7 @@ importfile(Val *f, int line) curio.infile = file; curio.nlsemi = 0; typecheckok = 1; + for(;;) { c = getc(); if(c == EOF) diff --git a/src/cmd/gc/mparith3.c b/src/cmd/gc/mparith3.c index 7b7e66668..b11a4f5f1 100644 --- a/src/cmd/gc/mparith3.c +++ b/src/cmd/gc/mparith3.c @@ -179,7 +179,7 @@ mpdivfltflt(Mpflt *a, Mpflt *b) double mpgetflt(Mpflt *a) { - int s, i; + int s, i, e; uvlong v, vm; double f; @@ -200,12 +200,12 @@ mpgetflt(Mpflt *a) a->exp -= 1; } - // the magic numbers (64, 63, 53, 10) are + // the magic numbers (64, 63, 53, 10, -1074) are // IEEE specific. this should be done machine // independently or in the 6g half of the compiler - // pick up the mantissa in a uvlong - s = 53; + // pick up the mantissa and a rounding bit in a uvlong + s = 53+1; v = 0; for(i=Mpnorm-1; s>=Mpscale; i--) { v = (v<<Mpscale) | a->val.a[i]; @@ -224,13 +224,26 @@ mpgetflt(Mpflt *a) if(s > 0) v = (v<<s) | (a->val.a[i]>>(Mpscale-s)); + // gradual underflow + e = Mpnorm*Mpscale + a->exp - 53; + if(e < -1074) { + s = -e - 1074; + if(s > 54) + s = 54; + v |= vm & ((1ULL<<s) - 1); + vm >>= s; + e = -1074; + } + //print("vm=%.16llux v=%.16llux\n", vm, v); // round toward even - if(v != (1ULL<<63) || (vm&1ULL) != 0) - vm += v>>63; + if(v != 0 || (vm&2ULL) != 0) + vm = (vm>>1) + (vm&1ULL); + else + vm >>= 1; f = (double)(vm); - f = ldexp(f, Mpnorm*Mpscale + a->exp - 53); + f = ldexp(f, e); if(a->val.neg) f = -f; diff --git a/src/cmd/gc/obj.c b/src/cmd/gc/obj.c index 0d0d70ac9..fbabe0d43 100644 --- a/src/cmd/gc/obj.c +++ b/src/cmd/gc/obj.c @@ -21,7 +21,7 @@ dumpobj(void) errorexit(); } - Bprint(bout, "%s\n", thestring); + Bprint(bout, "go object %s %s %s\n", getgoos(), thestring, getgoversion()); Bprint(bout, " exports automatically generated from\n"); Bprint(bout, " %s in package \"%s\"\n", curio.infile, localpkg->name); dumpexport(); diff --git a/src/cmd/gc/select.c b/src/cmd/gc/select.c index 5686e9599..58a147745 100644 --- a/src/cmd/gc/select.c +++ b/src/cmd/gc/select.c @@ -157,7 +157,7 @@ walkselect(Node *sel) if(n->left == N || isblank(n->left)) n->left = nodnil(); else if(n->left->op == ONAME && - (!n->colas || (n->class&PHEAP) == 0) && + (!n->colas || (n->left->class&PHEAP) == 0) && convertop(ch->type->type, n->left->type, nil) == OCONVNOP) { n->left = nod(OADDR, n->left, N); n->left->etype = 1; // pointer does not escape @@ -170,9 +170,9 @@ walkselect(Node *sel) typecheck(&a, Erv); r = nod(OAS, n->left, tmp); typecheck(&r, Etop); + cas->nbody = concat(list1(r), cas->nbody); cas->nbody = concat(n->ninit, cas->nbody); n->ninit = nil; - cas->nbody = concat(list1(r), cas->nbody); n->left = a; } } diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index cb5e2a831..0755ca3cd 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -203,6 +203,7 @@ fatal(char *fmt, ...) flusherrors(); +*(int*)0=0; print("%L: internal compiler error: ", lineno); va_start(arg, fmt); vfprint(1, fmt, arg); @@ -213,7 +214,7 @@ fatal(char *fmt, ...) if(strncmp(getgoversion(), "release", 7) == 0) { print("\n"); print("Please file a bug report including a short program that triggers the error.\n"); - print("http://code.google.com/p/go/issues/entry?template=compilerbug"); + print("http://code.google.com/p/go/issues/entry?template=compilerbug\n"); } hcrash(); errorexit(); diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 931d0327a..5edca964a 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -96,7 +96,7 @@ typecheck(Node **np, int top) Node *n, *l, *r; NodeList *args; int lno, ok, ntop; - Type *t, *missing, *have; + Type *t, *tp, *missing, *have; Sym *sym; Val v; char *why; @@ -552,6 +552,7 @@ reswitch: ok = Erv; goto ret; } + tp = t; if(isptr[t->etype] && t->type->etype != TINTER) { t = t->type; if(t == T) @@ -563,7 +564,7 @@ reswitch: if(lookdot(n, t, 1)) yyerror("%#N undefined (cannot refer to unexported field or method %S)", n, n->right->sym); else - yyerror("%#N undefined (type %T has no field or method %S)", n, t, n->right->sym); + yyerror("%#N undefined (type %T has no field or method %S)", n, tp, n->right->sym); goto error; } switch(n->op) { |