Bug 24880 - [4.1/4.2 regression] infinite loop on conversion of integer type with size clause
Summary: [4.1/4.2 regression] infinite loop on conversion of integer type with size cl...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.0.2
: P5 normal
Target Milestone: 4.3.1
Assignee: Eric Botcazou
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
: 29320 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-15 19:55 UTC by Nicolas Boulenguez
Modified: 2008-05-13 08:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.0.4
Last reconfirmed: 2008-04-12 16:06:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Boulenguez 2005-11-15 19:55:08 UTC
Explicit conversion from a numeric integer Type to Integer causes a crash of gcc
when the type is defined with a Size representation clause.
The bug disappears if the representation clause is removed or
if the range begins with 0.

Environment:
System: Linux simone 2.6.12.051101 #1 Tue Nov 1 17:19:34 CET 2005 i686 GNU/Linux
	Debian testing gnat-4.0 Version: 4.0.2-2
Architecture: i686
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu

How-To-Repeat:
---------------------------- File demo2.adb
procedure Demo2 is
   S : constant := Integer'Size;
   type Regoff_T is range -1 .. 2 ** (S-1);
   for Regoff_T'Size use S;
   B : Integer;
   C : Regoff_T;
begin
   B := Integer (C);
end Demo2;
--------------------------------------------- The crash message
~ gnatmake demo2
gcc-4.0 -c demo2.adb
gcc-4.0: Internal error: Erreur de segmentation (program gnat1)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions, see
<URL:file:///usr/share/doc/gcc-4.0/README.Bugs>.

gnatmake: "demo2.adb" compilation error
-------------------------------- with gnat version 3.4
~ gnatmake demo2
gcc-3.4 -c demo2.adb
demo2.adb:6:04: warning: "C" is never assigned a value
gnatbind -x demo2.ali
gnatlink demo2.ali
------------------------------------------------------
Comment 1 Nicolas Boulenguez 2005-11-15 19:55:08 UTC
Fix:
	none
Comment 2 Laurent GUERBY 2005-11-15 20:22:08 UTC
Confirmed on x86_64-linux and x86-linux. On x86 svn 4.0.3 and 4.1 gnat1 grows memory above 1GB and I had to kill the processes. 3.3.5 does not have the issue. On x86_64 gnat1 segfault immediately.
Comment 3 Gabriel Dos Reis 2007-02-03 15:51:08 UTC
Won't fix in GCC-4.0.4.  Adjusting milestone.
Comment 4 Samuel Tardieu 2008-04-12 15:40:08 UTC
Confirmed on 4.4.0:

+===========================GNAT BUG DETECTED==============================+
| 4.4.0 20080412 (experimental) (i686-pc-linux-gnu) Storage_Error stack overflow (or erroneous memory access)|
| Error detected at system.ads:155:5                                       |


There is an infinite loop between utils.c:convert and convert.c:convert_to_integer.
Comment 5 Eric Botcazou 2008-04-12 16:06:28 UTC
Known problem, investigating.
Comment 6 Samuel Tardieu 2008-04-12 16:25:09 UTC
*** Bug 29320 has been marked as a duplicate of this bug. ***
Comment 7 Eric Botcazou 2008-05-13 08:47:06 UTC
Subject: Bug 24880

Author: ebotcazou
Date: Tue May 13 08:46:18 2008
New Revision: 135257

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135257
Log:
	PR ada/24880
	PR ada/26635
	* utils.c (convert) <INTEGER_TYPE>: When converting an additive
	expression to an integral type with lower precision, use NOP_EXPR
	directly in a couple of special cases.


Added:
    trunk/gcc/testsuite/gnat.dg/conv_integer.adb
    trunk/gcc/testsuite/gnat.dg/discr7.adb
Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/utils.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Eric Botcazou 2008-05-13 08:47:41 UTC
Subject: Bug 24880

Author: ebotcazou
Date: Tue May 13 08:46:49 2008
New Revision: 135258

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135258
Log:
	PR ada/24880
	PR ada/26635
	* utils.c (convert) <INTEGER_TYPE>: When converting an additive
	expression to an integral type with lower precision, use NOP_EXPR
	directly in a couple of special cases.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gnat.dg/conv_integer.adb
    branches/gcc-4_3-branch/gcc/testsuite/gnat.dg/discr7.adb
Modified:
    branches/gcc-4_3-branch/gcc/ada/ChangeLog
    branches/gcc-4_3-branch/gcc/ada/utils.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 9 Eric Botcazou 2008-05-13 08:52:44 UTC
Fixed in the upcoming 4.3.1 release.