cmd/gc: don't squash complex literals when inlining.

Since this patch changes the way complex literals are written
in export data, there are a few other glitches.

Fixes #4159.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6674047
This commit is contained in:
Rémy Oudompheng 2012-10-17 20:33:44 +02:00
parent fcd5fd2ad4
commit a4682348c2
9 changed files with 465 additions and 642 deletions

View file

@ -379,7 +379,7 @@ Vconv(Fmt *fp)
return fmtprint(fp, "%#F", v->u.fval);
case CTCPLX:
if((fp->flags & FmtSharp) || fmtmode == FExp)
return fmtprint(fp, "(%F+%F)", &v->u.cval->real, &v->u.cval->imag);
return fmtprint(fp, "(%F+%Fi)", &v->u.cval->real, &v->u.cval->imag);
return fmtprint(fp, "(%#F + %#Fi)", &v->u.cval->real, &v->u.cval->imag);
case CTSTR:
return fmtprint(fp, "\"%Z\"", v->u.sval);

View file

@ -2039,6 +2039,8 @@ hidden_constant:
mpaddfixfix($2->val.u.xval, $4->val.u.xval, 0);
break;
}
$4->val.u.cval->real = $4->val.u.cval->imag;
mpmovecflt(&$4->val.u.cval->imag, 0.0);
$$ = nodcplxlit($2->val, $4->val);
}

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.5. */
/* A Bison parser, made by GNU Bison 2.6.2. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
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
@ -30,6 +30,15 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_Y_TAB_H
# define YY_Y_TAB_H
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
@ -141,12 +150,10 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2068 of yacc.c */
/* Line 2049 of yacc.c */
#line 28 "go.y"
Node* node;
@ -157,9 +164,8 @@ typedef union YYSTYPE
int i;
/* Line 2068 of yacc.c */
#line 163 "y.tab.h"
/* Line 2049 of yacc.c */
#line 169 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -168,4 +174,18 @@ typedef union YYSTYPE
extern YYSTYPE yylval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_Y_TAB_H */

View file

@ -681,7 +681,7 @@ func (p *gcParser) parseNumber() Const {
// ConstDecl = "const" ExportedName [ Type ] "=" Literal .
// Literal = bool_lit | int_lit | float_lit | complex_lit | string_lit .
// bool_lit = "true" | "false" .
// complex_lit = "(" float_lit "+" float_lit ")" .
// complex_lit = "(" float_lit "+" float_lit "i" ")" .
// rune_lit = "(" int_lit "+" int_lit ")" .
// string_lit = `"` { unicode_char } `"` .
//
@ -725,6 +725,7 @@ func (p *gcParser) parseConstDecl() {
re := p.parseNumber()
p.expect('+')
im := p.parseNumber()
p.expectKeyword("i")
p.expect(')')
x = Const{cmplx{re.val.(*big.Rat), im.val.(*big.Rat)}}
typ = Complex128.Underlying

View file

@ -687,7 +687,7 @@ func (p *gcParser) parseNumber() (x operand) {
// ConstDecl = "const" ExportedName [ Type ] "=" Literal .
// Literal = bool_lit | int_lit | float_lit | complex_lit | rune_lit | string_lit .
// bool_lit = "true" | "false" .
// complex_lit = "(" float_lit "+" float_lit ")" .
// complex_lit = "(" float_lit "+" float_lit "i" ")" .
// rune_lit = "(" int_lit "+" int_lit ")" .
// string_lit = `"` { unicode_char } `"` .
//
@ -728,6 +728,7 @@ func (p *gcParser) parseConstDecl() {
re := p.parseNumber()
p.expect('+')
im := p.parseNumber()
p.expectKeyword("i")
p.expect(')')
x.typ = Typ[UntypedComplex]
// TODO(gri) fix this

View file

@ -0,0 +1,15 @@
// 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.
package a
const N = 2+3i
func Func() []complex128 {
return []complex128{1, complex(2, 3), complex(4, 5)}
}
func Mul(z complex128) complex128 {
return z * (3 + 4i)
}

View file

@ -0,0 +1,30 @@
// 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.
package main
import "./a"
func main() {
s := a.Func()
if s[0] != 1 {
println(s[0])
panic("s[0] != 1")
}
if s[1] != 2+3i {
println(s[1])
panic("s[1] != 2+3i")
}
if s[2] != 4+5i {
println(s[2])
panic("s[2] != 4+5i")
}
x := 1 + 2i
y := a.Mul(x)
if y != (1+2i)*(3+4i) {
println(y)
panic("y != (1+2i)*(3+4i)")
}
}

11
test/fixedbugs/bug466.go Normal file
View file

@ -0,0 +1,11 @@
// rundir
// 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.
// Issue 4159: exported inlinable functions squash
// complex literals "a+bi" to "a+b".
package ignored