Bug 66138 - json decoder Decode function fails for some structure return values
Summary: json decoder Decode function fails for some structure return values
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: go (show other bugs)
Version: 5.1.1
: P3 critical
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-13 19:30 UTC by boger
Modified: 2015-11-07 01:26 UTC (History)
0 users

See Also:
Host: ppc64le, ppc64, x86_64
Target: ppc64le, ppc64, x86_64
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
failing testcase (838 bytes, text/plain)
2015-05-13 19:30 UTC, boger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description boger 2015-05-13 19:30:50 UTC
Created attachment 35538 [details]
failing testcase

I'm attaching a testcase that fails when built with gccgo on ppc64le and x86_64 from the gcc5 branch.  The test also fails using gccgo built from gcc trunk on ppc64le.  The same testcase works if compiled with gc for ppc64le and x86_64.

The problem occurs when creating a json decoder.  The difference in the cases that pass and fail is the format of the structure being passed to the Decode function to hold the return value.  The calls to DecodeContainerConfig2 demonstrate structures that work.  The calls to DecodeContainerConfig use structures that fail with gccgo.

Incorrect output looks like this:

./resconf
HC  &{1000 []}
CONFIG  &{host with memory at top level}
HC  &{1000 [/tmp:/tmp]}
CONFIG  &{host with memory at top level and a hostconfig}
HC  &{1000 [/tmp:/tmp]}
CONFIG  &{host with memory inside hostconfig}


ORIGINAL CODE CAUSE
CONFIG  &{host with memory at top level}
HC  &{0 []}
CONFIG  &{host with memory at top level and a hostconfig}
HC  &{0 []}
CONFIG  &{host with memory inside hostconfig}
HC  &{0 []}

Correct output:

./resconf
HC  &{1000 []}
CONFIG  &{host with memory at top level}
HC  &{1000 [/tmp:/tmp]}
CONFIG  &{host with memory at top level and a hostconfig}
HC  &{1000 [/tmp:/tmp]}
CONFIG  &{host with memory inside hostconfig}


ORIGINAL CODE CAUSE
CONFIG  &{host with memory at top level}
HC  &{1000 []}
CONFIG  &{host with memory at top level and a hostconfig}
HC  &{1000 [/tmp:/tmp]}
CONFIG  &{host with memory inside hostconfig}
HC  &{1000 [/tmp:/tmp]}
Comment 1 boger 2015-06-17 15:33:42 UTC
I am not sure, but this appears to be similar to the golang issue I opened yesterday https://github.com/golang/go/issues/11236 which was closed as a duplicate of https://github.com/golang/go/issues/7247.
Comment 2 boger 2015-06-23 16:26:25 UTC
Increasing priority since it is affecting correct execution of Docker when built with gccgo.
Comment 3 ian@gcc.gnu.org 2015-11-07 01:25:29 UTC
Author: ian
Date: Sat Nov  7 01:24:57 2015
New Revision: 229907

URL: https://gcc.gnu.org/viewcvs?rev=229907&root=gcc&view=rev
Log:
	PR go/66138
    reflect, encoding/json, encoding/xml: fix unexported embedded structs
    
    Bring in three changes from the master Go repository.  These changes
    will be in Go 1.6, but they are appropriate for gccgo now because they
    resolve a long-standing discrepancy between how gc and gccgo handle the
    PkgPath field for embedded unexported struct fields.  The core issue is
    described at https://golang.org/cl/7247.  This has been reported against
    gccgo as https://gcc.gnu.org/PR66138.
    
    The three changes being brought over are:
    
    https://golang.org/cl/14010
    
    reflect: adjust access to unexported embedded structs
    
    This CL changes reflect to allow access to exported fields and
    methods in unexported embedded structs for gccgo and after gc
    has been adjusted to disallow access to embedded unexported structs.
    
    Adresses #12367, #7363, #11007, and #7247.
    
    https://golang.org/cl/14011
    
    encoding/json: check for exported fields in embedded structs
    
    Addresses issue #12367.
    
    https://golang.org/cl/14012
    
    encoding/xml: check for exported fields in embedded structs
    
    Addresses issue #12367.
    
    Reviewed-on: https://go-review.googlesource.com/16723

Modified:
    trunk/gcc/go/gofrontend/MERGE
    trunk/libgo/go/encoding/json/decode_test.go
    trunk/libgo/go/encoding/json/encode.go
    trunk/libgo/go/encoding/xml/marshal_test.go
    trunk/libgo/go/encoding/xml/typeinfo.go
    trunk/libgo/go/reflect/export_test.go
    trunk/libgo/go/reflect/type.go
    trunk/libgo/go/reflect/value.go
Comment 4 ian@gcc.gnu.org 2015-11-07 01:26:15 UTC
Author: ian
Date: Sat Nov  7 01:25:43 2015
New Revision: 229908

URL: https://gcc.gnu.org/viewcvs?rev=229908&root=gcc&view=rev
Log:
	PR go/66138
    reflect, encoding/json, encoding/xml: fix unexported embedded structs
    
    Bring in three changes from the master Go repository.  These changes
    will be in Go 1.6, but they are appropriate for gccgo now because they
    resolve a long-standing discrepancy between how gc and gccgo handle the
    PkgPath field for embedded unexported struct fields.  The core issue is
    described at https://golang.org/cl/7247.  This has been reported against
    gccgo as https://gcc.gnu.org/PR66138.
    
    The three changes being brought over are:
    
    https://golang.org/cl/14010
    
    reflect: adjust access to unexported embedded structs
    
    This CL changes reflect to allow access to exported fields and
    methods in unexported embedded structs for gccgo and after gc
    has been adjusted to disallow access to embedded unexported structs.
    
    Adresses #12367, #7363, #11007, and #7247.
    
    https://golang.org/cl/14011
    
    encoding/json: check for exported fields in embedded structs
    
    Addresses issue #12367.
    
    https://golang.org/cl/14012
    
    encoding/xml: check for exported fields in embedded structs
    
    Addresses issue #12367.
    
    Reviewed-on: https://go-review.googlesource.com/16723

Modified:
    branches/gcc-5-branch/libgo/go/encoding/json/decode_test.go
    branches/gcc-5-branch/libgo/go/encoding/json/encode.go
    branches/gcc-5-branch/libgo/go/encoding/xml/marshal_test.go
    branches/gcc-5-branch/libgo/go/encoding/xml/typeinfo.go
    branches/gcc-5-branch/libgo/go/reflect/export_test.go
    branches/gcc-5-branch/libgo/go/reflect/type.go
    branches/gcc-5-branch/libgo/go/reflect/value.go
Comment 5 Ian Lance Taylor 2015-11-07 01:26:49 UTC
Should be fixed now.  Patch is on mainline and GCC 5 branch.