mirror of
https://github.com/golang/go
synced 2024-09-06 00:19:45 +00:00
cmd/cgo: use __typeof__, -w instead of typeof, -Wno-all
Suggested by iant in earlier CL. R=golang-dev, bradfitz, iant CC=golang-dev https://golang.org/cl/14920052
This commit is contained in:
parent
d220c9957c
commit
c8ddfd9ad1
|
@ -270,13 +270,13 @@ identifiers C.foo and C.bar, cgo generates this C program:
|
|||
|
||||
<preamble>
|
||||
#line 1 "not-declared"
|
||||
void __cgo_f_xxx_1(void) { typeof(foo) *__cgo_undefined__; }
|
||||
void __cgo_f_xxx_1(void) { __typeof__(foo) *__cgo_undefined__; }
|
||||
#line 1 "not-type"
|
||||
void __cgo_f_xxx_2(void) { foo *__cgo_undefined__; }
|
||||
#line 1 "not-const"
|
||||
void __cgo_f_xxx_3(void) { enum { __cgo_undefined__ = (foo)*1 }; }
|
||||
#line 2 "not-declared"
|
||||
void __cgo_f_xxx_1(void) { typeof(bar) *__cgo_undefined__; }
|
||||
void __cgo_f_xxx_1(void) { __typeof__(bar) *__cgo_undefined__; }
|
||||
#line 2 "not-type"
|
||||
void __cgo_f_xxx_2(void) { bar *__cgo_undefined__; }
|
||||
#line 2 "not-const"
|
||||
|
@ -300,14 +300,14 @@ that t1 is a type, v2 and v3 are variables or functions, and c4, c5,
|
|||
and c6 are constants, it generates:
|
||||
|
||||
<preamble>
|
||||
typeof(t1) *__cgo__1;
|
||||
typeof(v2) *__cgo__2;
|
||||
typeof(v3) *__cgo__3;
|
||||
typeof(c4) *__cgo__4;
|
||||
__typeof__(t1) *__cgo__1;
|
||||
__typeof__(v2) *__cgo__2;
|
||||
__typeof__(v3) *__cgo__3;
|
||||
__typeof__(c4) *__cgo__4;
|
||||
enum { __cgo_enum__4 = c4 };
|
||||
typeof(c5) *__cgo__5;
|
||||
__typeof__(c5) *__cgo__5;
|
||||
enum { __cgo_enum__5 = c5 };
|
||||
typeof(c6) *__cgo__6;
|
||||
__typeof__(c6) *__cgo__6;
|
||||
enum { __cgo_enum__6 = c6 };
|
||||
|
||||
long long __cgo_debug_data[] = {
|
||||
|
|
|
@ -288,7 +288,7 @@ func (p *Package) guessKinds(f *File) []*Name {
|
|||
// For each name, we generate these lines, where xxx is the index in toSniff plus one.
|
||||
//
|
||||
// #line xxx "not-declared"
|
||||
// void __cgo_f_xxx_1(void) { typeof(name) *__cgo_undefined__; }
|
||||
// void __cgo_f_xxx_1(void) { __typeof__(name) *__cgo_undefined__; }
|
||||
// #line xxx "not-type"
|
||||
// void __cgo_f_xxx_2(void) { name *__cgo_undefined__; }
|
||||
// #line xxx "not-const"
|
||||
|
@ -309,7 +309,7 @@ func (p *Package) guessKinds(f *File) []*Name {
|
|||
|
||||
for i, n := range names {
|
||||
fmt.Fprintf(&b, "#line %d \"not-declared\"\n"+
|
||||
"void __cgo_f_%d_1(void) { typeof(%s) *__cgo_undefined__; }\n"+
|
||||
"void __cgo_f_%d_1(void) { __typeof__(%s) *__cgo_undefined__; }\n"+
|
||||
"#line %d \"not-type\"\n"+
|
||||
"void __cgo_f_%d_2(void) { %s *__cgo_undefined__; }\n"+
|
||||
"#line %d \"not-const\"\n"+
|
||||
|
@ -406,14 +406,14 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
|||
// for symbols in the object file, so it is not enough to print the
|
||||
// preamble and hope the symbols we care about will be there.
|
||||
// Instead, emit
|
||||
// typeof(names[i]) *__cgo__i;
|
||||
// __typeof__(names[i]) *__cgo__i;
|
||||
// for each entry in names and then dereference the type we
|
||||
// learn for __cgo__i.
|
||||
var b bytes.Buffer
|
||||
b.WriteString(f.Preamble)
|
||||
b.WriteString(builtinProlog)
|
||||
for i, n := range names {
|
||||
fmt.Fprintf(&b, "typeof(%s) *__cgo__%d;\n", n.C, i)
|
||||
fmt.Fprintf(&b, "__typeof__(%s) *__cgo__%d;\n", n.C, i)
|
||||
if n.Kind == "const" {
|
||||
fmt.Fprintf(&b, "enum { __cgo_enum__%d = %s };\n", i, n.C)
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ func gccTmp() string {
|
|||
// the input.
|
||||
func (p *Package) gccCmd() []string {
|
||||
c := append(p.gccBaseCmd(),
|
||||
"-Wno-all", // no warnings
|
||||
"-w", // no warnings
|
||||
"-Wno-error", // warnings are not errors
|
||||
"-o"+gccTmp(), // write object to tmp
|
||||
"-gdwarf-2", // generate DWARF v2 debugging symbols
|
||||
|
@ -1082,7 +1082,7 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
|
|||
sub := c.Type(dt.Type, pos)
|
||||
t.Align = sub.Align
|
||||
gt.Elt = sub.Go
|
||||
t.C.Set("typeof(%s[%d])", sub.C, dt.Count)
|
||||
t.C.Set("__typeof__(%s[%d])", sub.C, dt.Count)
|
||||
|
||||
case *dwarf.BoolType:
|
||||
t.Go = c.bool
|
||||
|
@ -1220,7 +1220,7 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
|
|||
case "class", "union":
|
||||
t.Go = c.Opaque(t.Size)
|
||||
if t.C.Empty() {
|
||||
t.C.Set("typeof(unsigned char[%d])", t.Size)
|
||||
t.C.Set("__typeof__(unsigned char[%d])", t.Size)
|
||||
}
|
||||
t.Align = 1 // TODO: should probably base this on field alignment.
|
||||
typedef[name.Name] = t
|
||||
|
|
Loading…
Reference in a new issue