]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: more robust detection of clang
authorMatthew Dempsky <mdempsky@google.com>
Sat, 18 Apr 2015 00:05:47 +0000 (17:05 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 18 Apr 2015 01:11:44 +0000 (01:11 +0000)
Fixes #10453.

Change-Id: I77470279865d4c954df615d6594c69edf68c28ca
Reviewed-on: https://go-review.googlesource.com/9090
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/cgo/gcc.go
src/cmd/cgo/main.go
src/cmd/cgo/out.go

index 3ec753f55eef7370ea5da7cd7e858ad23b5247b3..694c88c7b3606ec87ce8086409d8389e5a12be4b 100644 (file)
@@ -199,6 +199,10 @@ func (p *Package) loadDefines(f *File) {
                        val = strings.TrimSpace(line[tabIndex:])
                }
 
+               if key == "__clang__" {
+                       p.GccIsClang = true
+               }
+
                if n := f.Name[key]; n != nil {
                        if *debugDefine {
                                fmt.Fprintf(os.Stderr, "#define %s %s\n", key, val)
@@ -762,7 +766,7 @@ func (p *Package) gccCmd() []string {
                "-c",          // do not link
                "-xc",         // input language is C
        )
-       if strings.Contains(c[0], "clang") {
+       if p.GccIsClang {
                c = append(c,
                        "-ferror-limit=0",
                        // Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn)
index 41abb2c672c35706ee10b69e9872516a44bb7dba..13ab9659d74ccd056e2f01528b0c073fb424e24c 100644 (file)
@@ -33,6 +33,7 @@ type Package struct {
        PtrSize     int64
        IntSize     int64
        GccOptions  []string
+       GccIsClang  bool
        CgoFlags    map[string][]string // #cgo flags (CFLAGS, LDFLAGS)
        Written     map[string]bool
        Name        map[string]*Name // accumulated Name from Files
index 11a1cffd181923a80941e1304088220b4a69ae5b..fd8ebcc4d91210968ce2c916f92ec4c45dcff033 100644 (file)
@@ -626,7 +626,7 @@ func (p *Package) writeGccgoOutputFunc(fgcc *os.File, n *Name) {
 // and http://golang.org/issue/5603.
 func (p *Package) packedAttribute() string {
        s := "__attribute__((__packed__"
-       if !strings.Contains(p.gccBaseCmd()[0], "clang") && (goarch == "amd64" || goarch == "386") {
+       if !p.GccIsClang && (goarch == "amd64" || goarch == "386") {
                s += ", __gcc_struct__"
        }
        return s + "))"