This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ada/29762] New: invalid index constraint causes GNAT to crash
- From: "mayerff at studi dot informatik dot uni-stuttgart dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Nov 2006 13:30:54 -0000
- Subject: [Bug ada/29762] New: invalid index constraint causes GNAT to crash
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I wanted to compile an Ada package I am writing as a student at the University
of Stuttgart, Germany.
The following happened:
$ gnatmake -gnaty3acefhiklmnrpt permutations.adb
gcc -c -gnaty3acefhiklmnrpt permutations.adb
+===========================GNAT BUG DETECTED==============================+
| 3.3 20040913 (GNAT for Mac OS X build 1650) (powerpc-unknown-darwin) |
| Assert_Failure sinfo.adb:1593 |
| Error detected at permutations.adb:68:7 |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html. |
| Include the entire contents of this bug box in the report. |
| Include the exact gcc or gnatmake command that you entered. |
| Also include sources listed below in gnatchop format |
| concatenated together with no headers between files. |
+==========================================================================+
Please include these source files with error report
permutations.adb
permutations.ads
list may be incomplete
permutations.adb:80:23: (style) space required
compilation abandoned
gnatmake: "permutations.adb" compilation error
The source files:
permutations.adb:
-- FILE: permutations.adb
--
-- PROJECT: Programmieruebungen, Uebungsblatt 02
-- VERSION: 1.0
-- DATE: 08 Nov 2006
-- AUTHOR: Fritjof A. Mayer
--
------------------------------------------------------------------------------
--
-- PACKAGE BODY Permutations
--
package body Permutations is
-- FUNCTION Next_Perm
--
-- Originally written on 10 Nov 2005
-- Blatt 2, Aufgabe 3, Programmierkurs I, WS05/06
-- by Fritjof A. Mayer
--
-- Generates next permutation.
-- Algorithm taken from "Einfuehrung in die Informatik I WS05/06"
function Next_Perm (Perm : Permutation) return Permutation is
Next_P : Permutation (Perm'Range) := Perm;
I, J, K, Smallest, Trans : Natural;
N : constant Natural := Perm'Last;
begin
-- search backwards for P (I) < P (I + 1)
-- starting at I = N - 1
I := N - 1;
while I >= 1 and Perm (I) > Perm (I + 1) loop
I := I - 1;
end loop;
-- search forwards for smallest Z > P (I), Z = P (J)
-- starting at J = I + 1
Smallest := I + 1;
for J in (I + 1) .. N loop
if Perm (J) < Perm (Smallest) and Perm (J) > Perm (I) then
Smallest := J;
end if;
end loop;
J := Smallest;
-- swap P (I) and P (J) in next permutation
Next_P (I) := Perm (J);
Next_P (J) := Perm (I);
-- sort elements P (I + 1) .. P (N)
-- by inverting their sequence
K := 0;
while (I + 1) + K < N - K loop
Trans := Next_P ((I + 1) + K);
Next_P ((I + 1) + K) := Next_P (N - K);
Next_P (N - K) := Trans;
K := K + 1;
end loop;
return Next_P;
end Next_Perm;
-- FUNCTION Word_Perm
--
-- Generates all permutations of a word, first and last
-- character are not permuted
--
-- Example: ...
--
function Word_Perm (Word : String) return P_Words is
All_Perms : P_Words (1 .. (Word'Length - 2)**2, Word'Length);
Perm : Permutation (1 .. Word'Length - 2);
begin
for I in Perm'Range loop
Perm (I) := I;
end loop;
for I in All_Perms'Range loop
All_Perms (I, 1) := Word (Word'First);
for J in Perm'Range loop
All_Perms (I, J) := Word (Perm (J));
end loop;
All_Perms (I,Word'Length) := Word (Word'Last);
Perm := Next_Perm (Perm);
end loop;
return All_Perms;
end Word_Perm;
end Permutations;
permutations.ads:
package Permutations is
type Permutation is array (Positive range <>) of Positive;
type P_Words is array (Positive range <>, Positive range <>) of Character;
function Next_Perm (Perm : Permutation) return Permutation;
end Permutations;
----------------------------------------------------------------
----------------------------------------------------------------
I think the problem is here:
...
function Word_Perm (Word : String) return P_Words is
All_Perms : P_Words (1 .. (Word'Length - 2)**2, Word'Length);
Perm : Permutation (1 .. Word'Length - 2);
begin
...
P_Words needs index constraints, those are ranges.
1 .. (Word'Length - 2)**2 is a range
Word'Length is just a number and no range.
Normally i should receive an error message: invalid index constraint
When I change this to
All_Perms : P_Words (1 .. (Word'Length - 2)**2,
1 .. Word'Length);
it compiles without errors.
--
Summary: invalid index constraint causes GNAT to crash
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mayerff at studi dot informatik dot uni-stuttgart dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29762