Bug 86667 - [7/8/9 Regression] can no longer traverse environment table
Summary: [7/8/9 Regression] can no longer traverse environment table
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.3.0
: P4 normal
Target Milestone: 7.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 86666 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-07-25 01:45 UTC by urbanjost
Modified: 2018-07-26 21:36 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 6.4.0
Known to fail: 7.3.0, 8.1.0, 9.0
Last reconfirmed: 2018-07-25 00:00:00


Attachments
fortran module and example program that used to print environment table (793 bytes, text/plain)
2018-07-25 01:45 UTC, urbanjost
Details
C code for interfacing to Fortran for printing environment table (675 bytes, text/x-csrc)
2018-07-25 01:47 UTC, urbanjost
Details

Note You need to log in before you can comment on or make changes to this bug.
Description urbanjost 2018-07-25 01:45:02 UTC
Created attachment 44433 [details]
fortran module and example program that used to print environment table

Program could read process environment table and print it up through at least GNU/gfortran 6.4.  Now at 7.0.3 it loops showing first entry fron environment table several hundred times and then fails with a segfault.
Comment 1 urbanjost 2018-07-25 01:47:10 UTC
Created attachment 44434 [details]
C code for interfacing to Fortran for printing environment table
Comment 2 Andrew Pinski 2018-07-25 02:13:21 UTC
*** Bug 86666 has been marked as a duplicate of this bug. ***
Comment 3 Dominique d'Humieres 2018-07-25 08:33:24 UTC
Confirmed. The change occurred between revisions r237590 (2016-06-20, OK) and r238821 (2016-07-28, wrong code.
Comment 4 Dominique d'Humieres 2018-07-25 08:52:17 UTC
If I compile the C file with r237590 and link the object file to the fortran file compiled with any revision (I have tried), the test works. This looks as a C bug rather than a fortran one.

Note that compiling the C file with -Wall gives

pr86667.c: In function 'my_initenv':
pr86667.c:39:7: warning: value computed is not used [-Wunused-value]
       *ep++;
       ^~~~~
pr86667.c: In function 'my_readenv':
pr86667.c:54:14: warning: operation on 'ep' may be undefined [-Wsequence-point]
       *ep=*ep++;
            ~~^~

Also I get the warning (on darwin)

ld: warning: tentative definition of '_longest_env_variable' with size 8 from '/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccDHXTrU.o' is being replaced by real definition of smaller size 4 from 'pr86667.o'
Comment 5 Dominique d'Humieres 2018-07-25 13:02:15 UTC
The test works as expected if I replace

      *ep=*ep++;

with

      *ep++;

in the C file.
Comment 6 Andreas Schwab 2018-07-25 13:13:40 UTC
*ep=*ep++ is undefined.
Comment 7 urbanjost 2018-07-26 21:36:43 UTC
Did not mean to get a debug session for the code. The code had been working for several years and "broke" when I updated gfortran (and incidently, gcc). Thanks to everyone for looking at it so promptly. Wasted a bunch of time condensing the Fortran down to a simple reproducer, when it was in the C all along.