From 6634e3432d7e8311013dc96c1e78a11d4a2e2a3c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 12 Nov 2009 00:22:45 -0800 Subject: [PATCH] cc, ld: fix more gcc 4.3 -O2 compile bugs same as https://golang.org/cl/152088 in more files. Fixes #83. R=r, r1 https://golang.org/cl/152091 --- src/cmd/cc/lex.c | 3 +-- src/cmd/ld/go.c | 4 ++-- src/cmd/ld/lib.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/cc/lex.c b/src/cmd/cc/lex.c index ff80bfb324a..9fbf3a3acdd 100644 --- a/src/cmd/cc/lex.c +++ b/src/cmd/cc/lex.c @@ -411,8 +411,7 @@ lookup(void) h += *p++; } n = (p - symb) + 1; - if((int32)h < 0) - h = ~h; + h &= 0xffffff; h %= NHASH; c = symb[0]; for(s = hash[h]; s != S; s = s->link) { diff --git a/src/cmd/ld/go.c b/src/cmd/ld/go.c index aa006a847ef..8f0e66d3306 100644 --- a/src/cmd/ld/go.c +++ b/src/cmd/ld/go.c @@ -42,8 +42,8 @@ hashstr(char *name) h = 0; for(cp = name; *cp; h += *cp++) h *= 1119; - if(h < 0) - h = ~h; + // not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it. + h &= 0xffffff; return h; } diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 99a76558d37..4a518c79b1e 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -384,8 +384,8 @@ lookup(char *symb, int v) for(p=symb; c = *p; p++) h = h+h+h + c; l = (p - symb) + 1; - if(h < 0) - h = ~h; + // not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it. + h &= 0xffffff; h %= NHASH; for(s = hash[h]; s != S; s = s->link) if(s->version == v)