diff --git a/include/libc.h b/include/libc.h index 9486b11430a..1440209e30a 100644 --- a/include/libc.h +++ b/include/libc.h @@ -374,7 +374,7 @@ extern char* unsharp(char*); /* command line */ extern char *argv0; extern void __fixargv0(void); -#define ARGBEGIN for((argv0?0:(argv0=(__fixargv0(),*argv))),argv++,argc--;\ +#define ARGBEGIN for((void)(argv0?0:(argv0=(__fixargv0(),*argv))),argv++,argc--;\ argv[0] && argv[0][0]=='-' && argv[0][1];\ argc--, argv++) {\ char *_args, *_argt;\ diff --git a/misc/cgo/testso/test.bash b/misc/cgo/testso/test.bash index ecef873c8d6..5f113d21629 100755 --- a/misc/cgo/testso/test.bash +++ b/misc/cgo/testso/test.bash @@ -4,7 +4,7 @@ # license that can be found in the LICENSE file. set -e -gcc $(go env GOGCCFLAGS) -shared -o libcgosotest.so cgoso_c.c +$(go env CC) $(go env GOGCCFLAGS) -shared -o libcgosotest.so cgoso_c.c go build main.go LD_LIBRARY_PATH=. ./main rm -f libcgosotest.so main diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 1449a8d6b58..ad28ec18cb2 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -391,9 +391,9 @@ func (p *Package) guessKinds(f *File) []*Name { b.WriteString(builtinProlog) b.WriteString(f.Preamble) b.WriteString("void __cgo__f__(void) {\n") - b.WriteString("#line 0 \"cgo-test\"\n") + b.WriteString("#line 1 \"cgo-test\"\n") for i, n := range toSniff { - fmt.Fprintf(&b, "%s; enum { _cgo_enum_%d = %s }; /* cgo-test:%d */\n", n.C, i, n.C, i) + fmt.Fprintf(&b, "%s; /* #%d */\nenum { _cgo_enum_%d = %s }; /* #%d */\n", n.C, i, i, n.C, i) } b.WriteString("}\n") stderr := p.gccErrors(b.Bytes()) @@ -423,14 +423,18 @@ func (p *Package) guessKinds(f *File) []*Name { if err != nil { continue } + i = (i - 1) / 2 what := "" switch { default: continue - case strings.Contains(line, ": useless type name in empty declaration"): + case strings.Contains(line, ": useless type name in empty declaration"), + strings.Contains(line, ": declaration does not declare anything"), + strings.Contains(line, ": unexpected type name"): what = "type" isConst[i] = false - case strings.Contains(line, ": statement with no effect"): + case strings.Contains(line, ": statement with no effect"), + strings.Contains(line, ": expression result unused"): what = "not-type" // const or func or var case strings.Contains(line, "undeclared"): error_(token.NoPos, "%s", strings.TrimSpace(line[colon+1:])) @@ -731,14 +735,19 @@ func (p *Package) rewriteRef(f *File) { } } -// gccName returns the name of the compiler to run. Use $GCC if set in +// gccName returns the name of the compiler to run. Use $CC if set in // the environment, otherwise just "gcc". -func (p *Package) gccName() (ret string) { - if ret = os.Getenv("GCC"); ret == "" { - ret = "gcc" +func (p *Package) gccName() string { + // Use $CC if set, since that's what the build uses. + if ret := os.Getenv("CC"); ret != "" { + return ret } - return + // Fall back to $GCC if set, since that's what we used to use. + if ret := os.Getenv("GCC"); ret != "" { + return ret + } + return "gcc" } // gccMachine returns the gcc -m flag to use, either "-m32", "-m64" or "-marm". @@ -771,6 +780,13 @@ func (p *Package) gccCmd() []string { "-c", // do not link "-xc", // input language is C } + if strings.Contains(p.gccName(), "clang") { + c = append(c, + "-ferror-limit=0", + "-Wno-unneeded-internal-declaration", + ) + } + c = append(c, p.GccOptions...) c = append(c, p.gccMachine()...) c = append(c, "-") //read input from standard input diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index afa0c470eb8..eb72074ec8f 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -409,7 +409,6 @@ static char *proto_gccargs[] = { "-Wno-comment", "-Werror", "-fno-common", - "-ggdb", "-pipe", "-O2", }; @@ -552,7 +551,7 @@ static void install(char *dir) { char *name, *p, *elem, *prefix, *exe; - bool islib, ispkg, isgo, stale; + bool islib, ispkg, isgo, stale, clang; Buf b, b1, path; Vec compile, files, link, go, missing, clean, lib, extra; Time ttarg, t; @@ -601,9 +600,14 @@ install(char *dir) xgetenv(&b, "CC"); if(b.len == 0) bprintf(&b, "gcc"); + clang = contains(bstr(&b), "clang"); splitfields(&gccargs, bstr(&b)); for(i=0; i