@@ -347,7 +347,7 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
347
347
if v == nil {
348
348
v = fn .lookup (obj , escaping )
349
349
}
350
- return & address {addr : v , expr : e }
350
+ return & address {addr : v , pos : e . Pos (), expr : e }
351
351
352
352
case * ast.CompositeLit :
353
353
t := deref (fn .Pkg .typeOf (e ))
@@ -359,7 +359,7 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
359
359
}
360
360
v .Comment = "complit"
361
361
b .compLit (fn , v , e , true ) // initialize in place
362
- return & address {addr : v , expr : e }
362
+ return & address {addr : v , pos : e . Lbrace , expr : e }
363
363
364
364
case * ast.ParenExpr :
365
365
return b .addr (fn , e .X , escaping )
@@ -378,6 +378,7 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
378
378
last := len (sel .Index ()) - 1
379
379
return & address {
380
380
addr : emitFieldSelection (fn , v , sel .Index ()[last ], true , e .Sel ),
381
+ pos : e .Sel .Pos (),
381
382
expr : e .Sel ,
382
383
}
383
384
@@ -410,10 +411,10 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
410
411
}
411
412
v .setPos (e .Lbrack )
412
413
v .setType (et )
413
- return & address {addr : fn .emit (v ), expr : e }
414
+ return & address {addr : fn .emit (v ), pos : e . Lbrack , expr : e }
414
415
415
416
case * ast.StarExpr :
416
- return & address {addr : b .expr (fn , e .X ), starPos : e .Star , expr : e }
417
+ return & address {addr : b .expr (fn , e .X ), pos : e .Star , expr : e }
417
418
}
418
419
419
420
panic (fmt .Sprintf ("unexpected address expression: %T" , e ))
@@ -891,7 +892,7 @@ func (b *builder) emitCallArgs(fn *Function, sig *types.Signature, e *ast.CallEx
891
892
}
892
893
iaddr .setType (types .NewPointer (vt ))
893
894
fn .emit (iaddr )
894
- emitStore (fn , iaddr , arg )
895
+ emitStore (fn , iaddr , arg , arg . Pos () )
895
896
}
896
897
s := & Slice {X : a }
897
898
s .setType (st )
@@ -1044,17 +1045,19 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1044
1045
switch t := typ .Underlying ().(type ) {
1045
1046
case * types.Struct :
1046
1047
if ! isZero && len (e .Elts ) != t .NumFields () {
1047
- emitMemClear (fn , addr )
1048
+ emitMemClear (fn , addr , e . Lbrace )
1048
1049
isZero = true
1049
1050
}
1050
1051
for i , e := range e .Elts {
1051
1052
fieldIndex := i
1053
+ pos := e .Pos ()
1052
1054
if kv , ok := e .(* ast.KeyValueExpr ); ok {
1053
1055
fname := kv .Key .(* ast.Ident ).Name
1054
1056
for i , n := 0 , t .NumFields (); i < n ; i ++ {
1055
1057
sf := t .Field (i )
1056
1058
if sf .Name () == fname {
1057
1059
fieldIndex = i
1060
+ pos = kv .Colon
1058
1061
e = kv .Value
1059
1062
break
1060
1063
}
@@ -1067,7 +1070,7 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1067
1070
}
1068
1071
faddr .setType (types .NewPointer (sf .Type ()))
1069
1072
fn .emit (faddr )
1070
- b .exprInPlace (fn , & address {addr : faddr , expr : e }, e , isZero )
1073
+ b .exprInPlace (fn , & address {addr : faddr , pos : pos , expr : e }, e , isZero )
1071
1074
}
1072
1075
1073
1076
case * types.Array , * types.Slice :
@@ -1086,7 +1089,7 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1086
1089
}
1087
1090
1088
1091
if ! isZero && int64 (len (e .Elts )) != at .Len () {
1089
- emitMemClear (fn , array )
1092
+ emitMemClear (fn , array , e . Lbrace )
1090
1093
isZero = true
1091
1094
}
1092
1095
@@ -1108,20 +1111,20 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1108
1111
}
1109
1112
iaddr .setType (types .NewPointer (at .Elem ()))
1110
1113
fn .emit (iaddr )
1111
- b .exprInPlace (fn , & address {addr : iaddr , expr : e }, e , isZero )
1114
+ b .exprInPlace (fn , & address {addr : iaddr , pos : e . Pos (), expr : e }, e , isZero )
1112
1115
}
1113
1116
if t != at { // slice
1114
1117
s := & Slice {X : array }
1115
1118
s .setPos (e .Lbrace )
1116
1119
s .setType (typ )
1117
- emitStore (fn , addr , fn .emit (s ))
1120
+ emitStore (fn , addr , fn .emit (s ), e . Lbrace )
1118
1121
}
1119
1122
1120
1123
case * types.Map :
1121
1124
m := & MakeMap {Reserve : intConst (int64 (len (e .Elts )))}
1122
1125
m .setPos (e .Lbrace )
1123
1126
m .setType (typ )
1124
- emitStore (fn , addr , fn .emit (m ))
1127
+ emitStore (fn , addr , fn .emit (m ), e . Lbrace )
1125
1128
for _ , e := range e .Elts {
1126
1129
e := e .(* ast.KeyValueExpr )
1127
1130
loc := & element {
@@ -1337,7 +1340,7 @@ func (b *builder) typeCaseBody(fn *Function, cc *ast.CaseClause, x Value, done *
1337
1340
// In a single-type case, y has that type.
1338
1341
// In multi-type cases, 'case nil' and default,
1339
1342
// y has the same type as the interface operand.
1340
- emitStore (fn , fn .addNamedLocal (obj ), x )
1343
+ emitStore (fn , fn .addNamedLocal (obj ), x , obj . Pos () )
1341
1344
}
1342
1345
fn .targets = & targets {
1343
1346
tail : fn .targets ,
@@ -1588,8 +1591,9 @@ func (b *builder) forStmt(fn *Function, s *ast.ForStmt, label *lblock) {
1588
1591
// rangeIndexed emits to fn the header for an integer-indexed loop
1589
1592
// over array, *array or slice value x.
1590
1593
// The v result is defined only if tv is non-nil.
1594
+ // forPos is the position of the "for" token.
1591
1595
//
1592
- func (b * builder ) rangeIndexed (fn * Function , x Value , tv types.Type ) (k , v Value , loop , done * BasicBlock ) {
1596
+ func (b * builder ) rangeIndexed (fn * Function , x Value , tv types.Type , pos token. Pos ) (k , v Value , loop , done * BasicBlock ) {
1593
1597
//
1594
1598
// length = len(x)
1595
1599
// index = -1
@@ -1623,7 +1627,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type) (k, v Value
1623
1627
}
1624
1628
1625
1629
index := fn .addLocal (tInt , token .NoPos )
1626
- emitStore (fn , index , intConst (- 1 ))
1630
+ emitStore (fn , index , intConst (- 1 ), pos )
1627
1631
1628
1632
loop = fn .newBasicBlock ("rangeindex.loop" )
1629
1633
emitJump (fn , loop )
@@ -1635,7 +1639,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type) (k, v Value
1635
1639
Y : vOne ,
1636
1640
}
1637
1641
incr .setType (tInt )
1638
- emitStore (fn , index , fn .emit (incr ))
1642
+ emitStore (fn , index , fn .emit (incr ), pos )
1639
1643
1640
1644
body := fn .newBasicBlock ("rangeindex.body" )
1641
1645
done = fn .newBasicBlock ("rangeindex.done" )
@@ -1814,10 +1818,10 @@ func (b *builder) rangeStmt(fn *Function, s *ast.RangeStmt, label *lblock) {
1814
1818
var loop , done * BasicBlock
1815
1819
switch rt := x .Type ().Underlying ().(type ) {
1816
1820
case * types.Slice , * types.Array , * types.Pointer : // *array
1817
- k , v , loop , done = b .rangeIndexed (fn , x , tv )
1821
+ k , v , loop , done = b .rangeIndexed (fn , x , tv , s . For )
1818
1822
1819
1823
case * types.Chan :
1820
- k , loop , done = b .rangeChan (fn , x , tk , s .TokPos )
1824
+ k , loop , done = b .rangeChan (fn , x , tk , s .For )
1821
1825
1822
1826
case * types.Map , * types.Basic : // string
1823
1827
k , v , loop , done = b .rangeIter (fn , x , tk , tv , s .For )
@@ -1955,7 +1959,7 @@ start:
1955
1959
// Function has named result parameters (NRPs).
1956
1960
// Perform parallel assignment of return operands to NRPs.
1957
1961
for i , r := range results {
1958
- emitStore (fn , fn .namedResults [i ], r )
1962
+ emitStore (fn , fn .namedResults [i ], r , s . Return )
1959
1963
}
1960
1964
}
1961
1965
// Run function calls deferred in this
@@ -2206,7 +2210,7 @@ func (p *Package) Build() {
2206
2210
done = init .newBasicBlock ("init.done" )
2207
2211
emitIf (init , emitLoad (init , initguard ), done , doinit )
2208
2212
init .currentBlock = doinit
2209
- emitStore (init , initguard , vTrue )
2213
+ emitStore (init , initguard , vTrue , token . NoPos )
2210
2214
2211
2215
// Call the init() function of each package we import.
2212
2216
for _ , pkg := range p .info .Pkg .Imports () {
@@ -2234,7 +2238,7 @@ func (p *Package) Build() {
2234
2238
// 1:1 initialization: var x, y = a(), b()
2235
2239
var lval lvalue
2236
2240
if v := varinit .Lhs [0 ]; v .Name () != "_" {
2237
- lval = & address {addr : p .values [v ].(* Global )}
2241
+ lval = & address {addr : p .values [v ].(* Global ), pos : v . Pos () }
2238
2242
} else {
2239
2243
lval = blank {}
2240
2244
}
@@ -2246,7 +2250,7 @@ func (p *Package) Build() {
2246
2250
if v .Name () == "_" {
2247
2251
continue
2248
2252
}
2249
- emitStore (init , p .values [v ].(* Global ), emitExtract (init , tuple , i ))
2253
+ emitStore (init , p .values [v ].(* Global ), emitExtract (init , tuple , i ), v . Pos () )
2250
2254
}
2251
2255
}
2252
2256
}
0 commit comments