public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/65772] New: With multiple return values including a function with side effects, incorrect value is returned
@ 2015-04-15 15:21 boger at us dot ibm.com
  2015-04-15 15:26 ` [Bug go/65772] " boger at us dot ibm.com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: boger at us dot ibm.com @ 2015-04-15 15:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65772

            Bug ID: 65772
           Summary: With multiple return values including a function with
                    side effects, incorrect value is returned
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: boger at us dot ibm.com
                CC: cmang at google dot com
            Target: ppc64le, x86_64


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug go/65772] With multiple return values including a function with side effects, incorrect value is returned
  2015-04-15 15:21 [Bug go/65772] New: With multiple return values including a function with side effects, incorrect value is returned boger at us dot ibm.com
@ 2015-04-15 15:26 ` boger at us dot ibm.com
  2015-04-15 15:31 ` boger at us dot ibm.com
  2015-04-15 15:56 ` ian at airs dot com
  2 siblings, 0 replies; 4+ messages in thread
From: boger at us dot ibm.com @ 2015-04-15 15:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65772

--- Comment #1 from boger at us dot ibm.com ---
Created attachment 35321
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35321&action=edit
testcase for bad return values


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug go/65772] With multiple return values including a function with side effects, incorrect value is returned
  2015-04-15 15:21 [Bug go/65772] New: With multiple return values including a function with side effects, incorrect value is returned boger at us dot ibm.com
  2015-04-15 15:26 ` [Bug go/65772] " boger at us dot ibm.com
@ 2015-04-15 15:31 ` boger at us dot ibm.com
  2015-04-15 15:56 ` ian at airs dot com
  2 siblings, 0 replies; 4+ messages in thread
From: boger at us dot ibm.com @ 2015-04-15 15:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65772

--- Comment #2 from boger at us dot ibm.com ---
When running the attached testcase on a platform with gccgo (ppc64le, x86_64),
the test fails due to incorrect return values from the function getList.  The
source line for the return looks like this:

return files, filepath.Walk(dir, visit)

The problem occurs because the array "files" is declared in the getList
function, and updated by the "visit" function which is passed to filepath.Walk.
 The array that is returned from getList does not reflect the updates made by
the visit.

When build with gc for either ppc64le or x86_64, the test case passes.

Expected output:

./myreturn
### Trying to list file: /tmp/mytest465364283/stuff in dir:
/tmp/mytest465364283 ###
### When walking:  found file: /tmp/mytest465364283/stuff ###
### PASS:  files returned !###


Incorrect output:

./myreturn
### Trying to list file: /tmp/mytest819936920/stuff in dir:
/tmp/mytest819936920 ###
### When walking:  found file: /tmp/mytest819936920/stuff ###
### FAIL:  no files returned ###


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug go/65772] With multiple return values including a function with side effects, incorrect value is returned
  2015-04-15 15:21 [Bug go/65772] New: With multiple return values including a function with side effects, incorrect value is returned boger at us dot ibm.com
  2015-04-15 15:26 ` [Bug go/65772] " boger at us dot ibm.com
  2015-04-15 15:31 ` boger at us dot ibm.com
@ 2015-04-15 15:56 ` ian at airs dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ian at airs dot com @ 2015-04-15 15:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65772

Ian Lance Taylor <ian at airs dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Ian Lance Taylor <ian at airs dot com> ---
The test case is invalid.  It works coincidentally with gc.

The order of evaluation rules for Go
(http://golang.org/ref/spec#Order_of_evaluation) do not specify when a variable
is read.  In a case like
    return files, filepath.Walk(dir, visit)
where files is updated by the visit function passed to filepath.Walk, the files
variable may be read either before or after calling filepath.Walk.  The gc
compiler is generating code that reads it after, the gccgo compiler is
generating code that reads it before.  Either is correct according to the
language spec.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-15 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15 15:21 [Bug go/65772] New: With multiple return values including a function with side effects, incorrect value is returned boger at us dot ibm.com
2015-04-15 15:26 ` [Bug go/65772] " boger at us dot ibm.com
2015-04-15 15:31 ` boger at us dot ibm.com
2015-04-15 15:56 ` ian at airs dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).