Commit 5c52404a authored by Russ Cox's avatar Russ Cox

gc: implicit type bug fix in export data

TBR=lvd
CC=golang-dev
https://golang.org/cl/5644064
parent 29df9373
...@@ -1058,7 +1058,7 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -1058,7 +1058,7 @@ exprfmt(Fmt *f, Node *n, int prec)
NodeList *l; NodeList *l;
Type *t; Type *t;
while(n && n->implicit) while(n && n->implicit && (n->op == OIND || n->op == OADDR))
n = n->left; n = n->left;
if(n == N) if(n == N)
...@@ -1160,13 +1160,13 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -1160,13 +1160,13 @@ exprfmt(Fmt *f, Node *n, int prec)
return fmtprint(f, "%N{ %,H }", n->right, n->list); return fmtprint(f, "%N{ %,H }", n->right, n->list);
case OPTRLIT: case OPTRLIT:
if (fmtmode == FExp && n->left->right->implicit == Implicit) if(fmtmode == FExp && n->left->implicit)
return fmtprint(f, "%N", n->left); return fmtprint(f, "%N", n->left);
return fmtprint(f, "&%N", n->left); return fmtprint(f, "&%N", n->left);
case OSTRUCTLIT: case OSTRUCTLIT:
if (fmtmode == FExp) { // requires special handling of field names if(fmtmode == FExp) { // requires special handling of field names
if(n->right->implicit == Implicit) if(n->implicit)
fmtstrcpy(f, "{"); fmtstrcpy(f, "{");
else else
fmtprint(f, "%T{", n->type); fmtprint(f, "%T{", n->type);
...@@ -1194,6 +1194,8 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -1194,6 +1194,8 @@ exprfmt(Fmt *f, Node *n, int prec)
case OMAPLIT: case OMAPLIT:
if(fmtmode == FErr) if(fmtmode == FErr)
return fmtprint(f, "%T literal", n->type); return fmtprint(f, "%T literal", n->type);
if(fmtmode == FExp && n->implicit)
return fmtprint(f, "{ %,H }", n->list);
return fmtprint(f, "%T{ %,H }", n->type, n->list); return fmtprint(f, "%T{ %,H }", n->type, n->list);
case OKEY: case OKEY:
......
...@@ -215,13 +215,6 @@ enum ...@@ -215,13 +215,6 @@ enum
EscNever, EscNever,
}; };
enum
{
Explicit,
Implicit, // don't print in output
ImplPtr, // OIND added by &T{ ... } literal
};
struct Node struct Node
{ {
// Tree structure. // Tree structure.
...@@ -257,7 +250,7 @@ struct Node ...@@ -257,7 +250,7 @@ struct Node
uchar used; uchar used;
uchar isddd; uchar isddd;
uchar readonly; uchar readonly;
uchar implicit; // Explicit, Implicit, ImplPtr. uchar implicit;
uchar addrtaken; // address taken, even if not moved to heap uchar addrtaken; // address taken, even if not moved to heap
uchar dupok; // duplicate definitions ok (for func) uchar dupok; // duplicate definitions ok (for func)
......
...@@ -808,7 +808,7 @@ uexpr: ...@@ -808,7 +808,7 @@ uexpr:
// Special case for &T{...}: turn into (*T){...}. // Special case for &T{...}: turn into (*T){...}.
$$ = $2; $$ = $2;
$$->right = nod(OIND, $$->right, N); $$->right = nod(OIND, $$->right, N);
$$->right->implicit = ImplPtr; $$->right->implicit = 1;
} else { } else {
$$ = nod(OADDR, $2, N); $$ = nod(OADDR, $2, N);
} }
......
...@@ -2008,7 +2008,8 @@ pushtype(Node *n, Type *t) ...@@ -2008,7 +2008,8 @@ pushtype(Node *n, Type *t)
if(n->right == N) { if(n->right == N) {
n->right = typenod(t); n->right = typenod(t);
n->right->implicit = 1; n->implicit = 1; // don't print
n->right->implicit = 1; // * is okay
} }
else if(debug['s']) { else if(debug['s']) {
typecheck(&n->right, Etype); typecheck(&n->right, Etype);
...@@ -2048,8 +2049,8 @@ typecheckcomplit(Node **np) ...@@ -2048,8 +2049,8 @@ typecheckcomplit(Node **np)
if(isptr[t->etype]) { if(isptr[t->etype]) {
// For better or worse, we don't allow pointers as the composite literal type, // For better or worse, we don't allow pointers as the composite literal type,
// except when using the &T syntax, which sets implicit to ImplPtr. // except when using the &T syntax, which sets implicit on the OIND.
if(n->right->implicit == Explicit) { if(!n->right->implicit) {
yyerror("invalid pointer type %T for composite literal (use &%T instead)", t, t->type); yyerror("invalid pointer type %T for composite literal (use &%T instead)", t, t->type);
goto error; goto error;
} }
......
This diff is collapsed.
/* A Bison parser, made by GNU Bison 2.3. */
/* Skeleton interface for Bison's Yacc-like parsers in C /* A Bison parser, made by GNU Bison 2.4.1. */
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 /* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc. Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation, either version 3 of the License, or
any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program. If not, see <http://www.gnu.org/licenses/>. */
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, you may create a larger work that contains /* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work part or all of the Bison parser skeleton and distribute that work
...@@ -29,10 +28,11 @@ ...@@ -29,10 +28,11 @@
special exception, which will cause the skeleton and the resulting special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public Bison output files to be licensed under the GNU General Public
License without this special exception. License without this special exception.
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
...@@ -146,22 +146,28 @@ ...@@ -146,22 +146,28 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE
#line 28 "go.y"
{ {
/* Line 1676 of yacc.c */
#line 28 "go.y"
Node* node; Node* node;
NodeList* list; NodeList* list;
Type* type; Type* type;
Sym* sym; Sym* sym;
struct Val val; struct Val val;
int i; int i;
}
/* Line 1529 of yacc.c. */
#line 160 "y.tab.h"
YYSTYPE; /* Line 1676 of yacc.c */
#line 165 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif #endif
extern YYSTYPE yylval; extern YYSTYPE yylval;
...@@ -36,6 +36,8 @@ func F6(S int) *U { ...@@ -36,6 +36,8 @@ func F6(S int) *U {
return &U{{S,S}} return &U{{S,S}}
} }
// Bug in the fix.
type PB struct { x int }
func (t *PB) Reset() { *t = PB{} }
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Use the functions in one.go so that the inlined
// forms get type-checked.
package three
import "./two"
var x = two.F()
var v = two.V
...@@ -19,3 +19,7 @@ func use() { ...@@ -19,3 +19,7 @@ func use() {
t.M() t.M()
t.MM() t.MM()
} }
var V = []one.PB{{}, {}}
func F() *one.PB
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go // $G $D/$F.dir/one.go && $G $D/$F.dir/two.go && $G $D/$F.dir/three.go
// Copyright 2011 The Go Authors. All rights reserved. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
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