Commit 93402383 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/cgo: more robust detection of clang

Fixes #10453.

Change-Id: I77470279865d4c954df615d6594c69edf68c28ca
Reviewed-on: https://go-review.googlesource.com/9090Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 05efc18c
...@@ -199,6 +199,10 @@ func (p *Package) loadDefines(f *File) { ...@@ -199,6 +199,10 @@ func (p *Package) loadDefines(f *File) {
val = strings.TrimSpace(line[tabIndex:]) val = strings.TrimSpace(line[tabIndex:])
} }
if key == "__clang__" {
p.GccIsClang = true
}
if n := f.Name[key]; n != nil { if n := f.Name[key]; n != nil {
if *debugDefine { if *debugDefine {
fmt.Fprintf(os.Stderr, "#define %s %s\n", key, val) fmt.Fprintf(os.Stderr, "#define %s %s\n", key, val)
...@@ -762,7 +766,7 @@ func (p *Package) gccCmd() []string { ...@@ -762,7 +766,7 @@ func (p *Package) gccCmd() []string {
"-c", // do not link "-c", // do not link
"-xc", // input language is C "-xc", // input language is C
) )
if strings.Contains(c[0], "clang") { if p.GccIsClang {
c = append(c, c = append(c,
"-ferror-limit=0", "-ferror-limit=0",
// Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn) // Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn)
......
...@@ -33,6 +33,7 @@ type Package struct { ...@@ -33,6 +33,7 @@ type Package struct {
PtrSize int64 PtrSize int64
IntSize int64 IntSize int64
GccOptions []string GccOptions []string
GccIsClang bool
CgoFlags map[string][]string // #cgo flags (CFLAGS, LDFLAGS) CgoFlags map[string][]string // #cgo flags (CFLAGS, LDFLAGS)
Written map[string]bool Written map[string]bool
Name map[string]*Name // accumulated Name from Files Name map[string]*Name // accumulated Name from Files
......
...@@ -626,7 +626,7 @@ func (p *Package) writeGccgoOutputFunc(fgcc *os.File, n *Name) { ...@@ -626,7 +626,7 @@ func (p *Package) writeGccgoOutputFunc(fgcc *os.File, n *Name) {
// and http://golang.org/issue/5603. // and http://golang.org/issue/5603.
func (p *Package) packedAttribute() string { func (p *Package) packedAttribute() string {
s := "__attribute__((__packed__" s := "__attribute__((__packed__"
if !strings.Contains(p.gccBaseCmd()[0], "clang") && (goarch == "amd64" || goarch == "386") { if !p.GccIsClang && (goarch == "amd64" || goarch == "386") {
s += ", __gcc_struct__" s += ", __gcc_struct__"
} }
return s + "))" return s + "))"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment