golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.84k stars 17.65k forks source link

Error while compile the latest release. #1843

Closed gopherbot closed 9 years ago

gopherbot commented 13 years ago

by milkline:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1.hg pull -u
2.cd src
3../make.bash

What is the expected output?
ALL TESTS PASSED

---
Installed Go for linux/386 in /home/you/go.
Installed commands in /home/you/go/bin.
*** You need to add /home/you/go/bin to your $PATH. ***
The compiler is 8g.

What do you see instead?

quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/unsafe.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/walk.c"
cat y.tab.c | sed '/ int yystate;/d; s/int yychar;/int yychar, yystate;/; s/static const
char \*const yytname/const char *yytname/' >y1.tab.c
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/cgen64.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/div.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/list.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/align.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/machcap.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/bits.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/mul.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/builtin.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/subr.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/gc/y1.tab.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c -I. -o pgen.o ../cc/pgen.c
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c -I. -o pswt.o ../cc/pswt.c
y.tab.c:5203:9: error: passing argument 1 of 'yyerror' discards 'const' qualifier from
pointer target type [-Werror]
/home/milkline/go/src/cmd/gc/go.h:1148:6: note: expected 'char *' but argument is of
type 'const char *'
cc1: all warnings being treated as errors

make[1]: *** [y1.tab.o] Error 1
make[1]: *** Waiting for unfinished jobs....
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/peep.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/reg.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/sgen.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/swt.c"
quietgcc -I"/home/milkline/go/include" -ggdb -O2 -c
"/home/milkline/go/src/cmd/8c/txt.c"
quietgcc -o 8c -L"/home/milkline/go"/lib cgen.o cgen64.o div.o list.o
machcap.o mul.o pgen.o pswt.o peep.o reg.o sgen.o swt.o txt.o ../8l/enam.o  ../cc/cc.a 
-lbio -l9 -lm 
cp 8c "/home/milkline/go/bin"/8c
make[1]: Leaving directory `/home/milkline/go/src/cmd/8c'
make[1]: Leaving directory `/home/milkline/go/src/cmd/gc'
make: *** [gc.install] error 2
make: Leaving“/home/milkline/go/src/cmd”

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Archlinux

Which revision are you using?  (hg identify)
e1e194eb5c8e (release-branch.r57)

Please provide any additional information below.
adg commented 13 years ago

Comment 1:

Seems like gcc 4.6 cares about const char * -> char *, where earlier versions didn't.
Ian, can you shed some light on this?

Status changed to Accepted.

ianlancetaylor commented 13 years ago

Comment 2:

The errors are:
y.tab.c:5203:9: error: passing argument 1 of 'yyerror' discards 'const' qualifier from
pointer target type [-Werror]
/home/milkline/go/src/cmd/gc/go.h:1148:6: note: expected 'char *' but argument is of
type 'const char *'
Nothing has changed in gcc.  More likely is a change in bison.  What version of bison
are you using?  What is line 5203 of the file src/cmd/gc/y.tab.c?
rsc commented 13 years ago

Comment 3:

The Go tree's C code assumes that you can pass a
string literal "hello" to a function expecting a char*.
Gcc appears to want you to pass such string literals
only to functions expecting const char*.
I don't know why this would have started showing up now.
Either we have to fix the tree or we have to find a
compiler flag that we can rely on even in old gcc
to silence the error.
Russ
ianlancetaylor commented 13 years ago

Comment 4:

gcc does not warn about passing a string literal to a function which expects char*,
unless you use the -Wwrite-strings option which quietgcc does not do.  There are in any
case many calls passing a string literal to yyerror, but the reported output only has
one error.  So it's not a matter of passing a string literal.  It's something else, but
I don't know what it is, because I don't know what that line in y.tab.c looks like. 
Line 5203 in my y.tab.c, generated by bison 2.4.1, has nothing close by which calls
yyerror.
gopherbot commented 13 years ago

Comment 5 by milkline:

[milkline@Pengyu-PC ~]$ bison -V
bison (GNU Bison) 2.5
Written by Robert Corbett and Richard Stallman.
line 5203 is :yyerror (yymsgp);
ianlancetaylor commented 13 years ago

Comment 6:

Thanks.  I built bison 2.5 and I can confirm that it pass a const char * variable to
yyerror, which is where this warning is coming from.  As far as I can see, we can either
extend the sed command which creates y1.tab.c to remove the "const", or we can change
yyerror to accept const char *.
E.g., adding this to the sed command works around the problem:
    s/char const \*yymsgp/char *yymsgp/
rsc commented 13 years ago

Comment 7:

Ian's sed fix LGTM.
ianlancetaylor commented 13 years ago

Comment 8:

This issue was closed by revision 9ef8ebafe46668a3164d99e061c3e8ff652a0b0.

Status changed to Fixed.

mrosset commented 13 years ago

Comment 9:

This problem still occurs for people using bison 2.5 and release. Should this possibly
be back ported to release? Or have people remove -Werror mean time, until a new release
it tagged?
adg commented 13 years ago

Comment 10:

I'm not sure that it impacts enough people to be worth back-porting the fix. We'll be
moving on to a new release before too long.
adg commented 13 years ago

Comment 11:

Issue #1978 has been merged into this issue.

adg commented 13 years ago

Comment 12:

Issue #1978 has been merged into this issue.