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

adonovan opened this issue Oct 29, 2014 · 3 comments


Copy link

commented Oct 29, 2014

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 (


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 (
//line /home/adonovan/test/blurgh.go:7

//line /home/adonovan/test/blurgh.go:6
//line /home/adonovan/test/blurgh.go:12

//line /home/adonovan/test/blurgh.go:11
var _ foo.Foo
var _ blah.Blah

This comment has been minimized.

Copy link

commented Oct 29, 2014

Comment 1:

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


This comment has been minimized.

Copy link

commented Oct 30, 2014

Comment 2:

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

@adonovan adonovan added new labels Oct 30, 2014

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014

@rsc rsc removed the repo-main label Apr 14, 2015


This comment has been minimized.

Copy link

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 Jun 8, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
5 participants
You can’t perform that action at this time.