Skip to content

Commit 6634e34

Browse files
committed
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
1 parent 6dbd142 commit 6634e34

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/cmd/cc/lex.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ lookup(void)
411411
h += *p++;
412412
}
413413
n = (p - symb) + 1;
414-
if((int32)h < 0)
415-
h = ~h;
414+
h &= 0xffffff;
416415
h %= NHASH;
417416
c = symb[0];
418417
for(s = hash[h]; s != S; s = s->link) {

src/cmd/ld/go.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ hashstr(char *name)
4242
h = 0;
4343
for(cp = name; *cp; h += *cp++)
4444
h *= 1119;
45-
if(h < 0)
46-
h = ~h;
45+
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
46+
h &= 0xffffff;
4747
return h;
4848
}
4949

src/cmd/ld/lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ lookup(char *symb, int v)
384384
for(p=symb; c = *p; p++)
385385
h = h+h+h + c;
386386
l = (p - symb) + 1;
387-
if(h < 0)
388-
h = ~h;
387+
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
388+
h &= 0xffffff;
389389
h %= NHASH;
390390
for(s = hash[h]; s != S; s = s->link)
391391
if(s->version == v)

0 commit comments

Comments
 (0)