Skip to content

cmd/compile: shallow copy of a struct does not always compile as MOVL #53810

@LeGamerDc

Description

@LeGamerDc
type Example struct {
  a, b int32
}
x := Example{x:1, y:1}
y := x

the y:=x will be compiled to two movl while the x:=Example{x:1, y:1} compiled to single movq.
it confuse me about the memory bevavior, assumpt we have one routine write x=Example{x:1, y:1} and another write x=Example{x:2, y:2}, according to the memory model, x will either be x:1,y:1 or x:2, y:2. how ever if we do

y:=x
fmt.Println(y.a, y.b)

then, we could get x:1, y:2 !!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.PerformanceWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions