lr->n = safeexpr(lr->n, init);
 
        nn = nil;
-       for(ll=nl, lr=nr; ll && lr; ll=ll->next, lr=lr->next)
+       for(ll=nl, lr=nr; ll && lr; ll=ll->next, lr=lr->next) {
+               // Do not generate 'x = x' during return. See issue 4014.
+               if(op == ORETURN && ll->n == lr->n)
+                       continue;
                nn = list(nn, ascompatee1(op, ll->n, lr->n, init));
+       }
 
        // cannot happen: caller checked that lists had same length
        if(ll || lr)
 
        i := 1
        _ = v[(i*4)/3]
 }
+
+func TestNoRaceReturn(t *testing.T) {
+       c := make(chan int)
+       noRaceReturn(c)
+       <-c
+}
+
+// Return used to do an implicit a = a, causing a read/write race
+// with the goroutine. Compiler has an optimization to avoid that now.
+// See issue 4014.
+func noRaceReturn(c chan int) (a, b int) {
+       a = 42
+       go func() {
+               _ = a
+               c <- 1
+       }()
+       return a, 10
+}