Bug 22217 - Z edit descriptor with negative numbers
Summary: Z edit descriptor with negative numbers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-06-28 13:45 UTC by Thomas Koenig
Modified: 2005-07-19 08:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-05 07:52:45


Attachments
Patch (538 bytes, patch)
2005-07-05 07:53 UTC, Francois-Xavier Coudert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2005-06-28 13:45:13 UTC
$ cat foo3.f90
program main
  i = -1
  print '(Z8)',i
end program main
$ gfortran foo3.f90
$ ./a.out
********
$ gfortran -v
Using built-in specs.
Target: ia64-unknown-linux-gnu
Configured with: ../gcc-4.1-20050625/configure --prefix=/home/zfkts --enable-
languages=c,f95
Thread model: posix
gcc version 4.1.0 20050625 (experimental)

The output should be

FFFFFFFF
Comment 1 Francois-Xavier Coudert 2005-06-29 20:53:37 UTC
Confirmed. This bug is due to my recent patch to support large integer kinds.
I'm thinking about how we should fix this.
Comment 2 Thomas Koenig 2005-06-30 08:29:59 UTC
It's probably easiest to have xtoa() and friends extract
the integer for themselves.

If you do this, don't forget to increase the size of buffer[]
so it can hold largest_integer_kind*8+1 characters for binary
representation.

Would it be possible to define a macro GFC_LARGEST_INTEGER_KIND 
in kinds.h?
Comment 3 Francois-Xavier Coudert 2005-07-05 07:52:43 UTC
For the GFC_LARGEST_INTEGER_KIND macro, there is already a GFC_INTEGER_LARGEST.
Or do you mean that GFC_LARGEST_INTEGER_KIND should be just 8 (or 16), not
GFC_INTEGER_8 (or GFC_INTEGER_16)?

As for this bug, the solution you mention was the one I thought of, but it means
changing prototypes. A better solution (at least, I think it is better) is to
have an extract_uint() function that does cast to GFC_UINTEGER_4 before casting
to GFC_UINTEGER_LARGEST.

Attached patch fixes the problem (for Z, O and B edit descriptors, with all kinds).

I'm leaving town tomorrow, won't have access to an internet connection and lots
of things to do before tomorrow. So, please feel free to test and commit this
patch! If nobody does it, I'll do it when I come back (in August).
Comment 4 Francois-Xavier Coudert 2005-07-05 07:53:19 UTC
Created attachment 9205 [details]
Patch
Comment 5 GCC Commits 2005-07-09 09:33:44 UTC
Subject: Bug 22217

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tkoenig@gcc.gnu.org	2005-07-09 09:33:32

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/io : write.c 
	libgfortran/runtime: error.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: negative-z-descriptor.f90 

Log message:
	2005-07-07  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
	Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/22217
	* io/write.c (extract_unit):  New function; extract
	ints as unsigned signed int of the correct size.
	* io/write.c (write_int):  Use it.
	* runtime/error.c:  Adjust copyright years.
	Adjust size of buffer to maximum that can occur.
	
	2005-07-07  Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/22217
	* gfortran.dg/negative-z-descriptor.f90:  New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.258&r2=1.259
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/write.c.diff?cvsroot=gcc&r1=1.39&r2=1.40
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/runtime/error.c.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5745&r2=1.5746
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/negative-z-descriptor.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Francois-Xavier Coudert 2005-07-19 08:18:04 UTC
No need to apply on 4.0 branch, since support for large kinds is only in
mainline. Fixed.