Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: leading whitespace in generated files is noncanonical #9019

Closed
adonovan opened this issue Oct 29, 2014 · 3 comments
Closed

cmd/cgo: leading whitespace in generated files is noncanonical #9019

adonovan opened this issue Oct 29, 2014 · 3 comments
Milestone

Comments

@adonovan
Copy link
Member

The output of cgo is not canonical according to gofmt, as it has an excessive number of
tabs preceding many source lines, notably the import paths (e.g. "fmt") inside
the import block, as the example below shows.  I suspect this is related to
printer.SourcePos mode and //line directives.

For what it's worth, I believe this behaviour is at least somewhat nondeterministic (it
caused my mapreduce consistency checks to fail), although I haven't succeeded in
reproducing that locally.

Deleting the blank line between the two imports hides the bug.

% go version
go version devel +6d6fbf7dee5b Mon Oct 20 11:10:03 2014 -0700 linux/amd64
% cat blurgh.go 
package blurgh

import (
        "blah"

        "foo"
)

import "C"

var _ foo.Foo
var _ blah.Blah
% go tool cgo blurgh.go 
% cat -t _obj/blurgh.cgo1.go 
// Created by cgo - DO NOT EDIT

//line /home/adonovan/test/blurgh.go:1
package blurgh
//line /home/adonovan/test/blurgh.go:4

//line /home/adonovan/test/blurgh.go:3
import (
^I^I^I^I^I"blah"
//line /home/adonovan/test/blurgh.go:7

//line /home/adonovan/test/blurgh.go:6
^I"foo"
)
//line /home/adonovan/test/blurgh.go:12

//line /home/adonovan/test/blurgh.go:11
var _ foo.Foo
var _ blah.Blah
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.5.

@adonovan
Copy link
Member Author

Comment 2:

(cgo's nondeterminism had a different cause.  I'll file a separate issue for that.)

@rsc
Copy link
Contributor

rsc commented Jun 8, 2015

Nondeterministic output is bad and should be fixed.

But non-gofmt'ed output is not a problem. People who care can run gofmt. (The build system doesn't care and doesn't expose these outputs.)

@rsc rsc closed this as completed Jun 8, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants