[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#226244: gcc -O3 -fprofile-arcs causes an array initalizer to be miscompiled



Package: gnat-3.3
Version: 1:3.3.3-0pre1
Severity: normal

This is where I gave up on narrowing it down.

--*---*---*-
-*-*-*-*-*-*
------------
------------
------------
------------
-*-*-*-*-*-*
--*---*---*-

is what it should look like,

------*---*-
-*-*-*-*-*-*
------------
------------
------------
------------
-*-*-*-*-*-*
--*---*---*-

is what it looks like with -O3 -fprofile-arcs. As you can see from the
initalizer below, a gold basilisk is missing from the board. If I remove
the upper two layers that aren't being printed out, it stops
miscompiling.

*** Makefile
GM=gnatmake
AOPTS=-O3 -fprofile-arcs
#AOPTS=-O3 #Works
#AOPTS=-fprofile-arcs #Works

all: drgnchss

dep:

undep:
	rm dep

drgnchss: drgnchss.adb board_types.ads print_board.adb
	$(GM) $(AOPTS) drgnchss

clean:
	rm *.ali *.o *.s *~ drgnchss b~* *.bb *.bbg *.da dep gmon.out *.gcov

*** board_types.ads
--  Board_Types contains all the fundamental types representing the game.

package Board_Types is

   --  Board_Types is and should continue to be conceptually pure. No
   --  global data or state.
   pragma Pure (Board_Types);

   type Board_Layer_Type is (Upper, Middle, Lower);

   type Piece_Type is
     (Sylph, Griffon, Dragon, King, Mage, Paladin, Thief,
      Cleric, Hero, Unicorn, Oliphant, Warrior, Dwarf, Basilisk,
      Elemental);
   type Player_Type is (Scarlet, Gold);
   type Board_Piece (Exists : Boolean := False) is record
      case Exists is
         when True =>
            Piece : Piece_Type;
            Player : Player_Type;
         when False =>
            null;
      end case;
   end record;
   type Row_Type is range 1 .. 8;
   type Column_Type is range 1 .. 12;
   type Board_Layer is array (Row_Type, Column_Type) of Board_Piece;
   type Board is array (Board_Layer_Type) of Board_Layer;
   type Board_Location is record
      Layer : Board_Layer_Type;
      Row : Row_Type;
      Column : Column_Type;
   end record;

   Initial_Board : constant Board;

private

   Initial_Board : constant Board :=
     (
      ((
        (Exists => False),
        (Exists => False),
        (True, Griffon, Gold ),
        (Exists => False),
        (Exists => False),
        (Exists => False),
        (True, Dragon, Gold ),
        (Exists => False),
        (Exists => False),
        (Exists => False),
        (True, Griffon, Gold ),
        (Exists => False)
       ),(
          (True, Sylph, Gold ),
          (Exists => False),
          (True, Sylph, Gold ),
          (Exists => False),
          (True, Sylph, Gold ),
          (Exists => False),
          (True, Sylph, Gold ),
          (Exists => False),
          (True, Sylph, Gold ),
          (Exists => False),
          (True, Sylph, Gold ),
          (Exists => False)
         ),(
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False)
           ),(
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False)
             ),(
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False)
               ),(
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False)
                 ),(
                    (True, Sylph, Scarlet ),
                    (Exists => False),
                    (True, Sylph, Scarlet ),
                    (Exists => False),
                    (True, Sylph, Scarlet ),
                    (Exists => False),
                    (True, Sylph, Scarlet ),
                    (Exists => False),
                    (True, Sylph, Scarlet ),
                    (Exists => False),
                    (True, Sylph, Scarlet ),
                    (Exists => False)
                   ),(
                      (Exists => False),
                      (Exists => False),
                      (True, Griffon, Scarlet ),
                      (Exists => False),
                      (Exists => False),
                      (Exists => False),
                      (True, Dragon, Scarlet ),
                      (Exists => False),
                      (Exists => False),
                      (Exists => False),
                      (True, Griffon, Scarlet ),
                      (Exists => False)
                     )),
      ((
        (True, Oliphant, Gold ),
        (True, Unicorn, Gold ),
        (True, Hero, Gold ),
        (True, Thief, Gold ),
        (True, Cleric, Gold ),
        (True, Mage, Gold ),
        (True, King, Gold ),
        (True, Paladin, Gold ),
        (True, Thief, Gold ),
        (True, Hero, Gold ),
        (True, Unicorn, Gold ),
        (True, Oliphant, Gold )
       ),(
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold ),
          (True, Warrior, Gold )
         ),(
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False)
           ),(
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False)
             ),(
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False)
               ),(
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False)
                 ),(
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet ),
                    (True, Warrior, Scarlet )
                   ),(
                      (True, Oliphant, Scarlet ),
                      (True, Unicorn, Scarlet ),
                      (True, Hero, Scarlet ),
                      (True, Thief, Scarlet ),
                      (True, Cleric, Scarlet ),
                      (True, Mage, Scarlet ),
                      (True, King, Scarlet ),
                      (True, Paladin, Scarlet ),
                      (True, Thief, Scarlet ),
                      (True, Hero, Scarlet ),
                      (True, Unicorn, Scarlet ),
                      (True, Oliphant, Scarlet )
                     )),
      ((
        (Exists => False),
        (Exists => False),
        (True, Basilisk, Gold ),
        (Exists => False),
        (Exists => False),
        (Exists => False),
        (True, Elemental, Gold ),
        (Exists => False),
        (Exists => False),
        (Exists => False),
        (True, Basilisk, Gold ),
        (Exists => False)
       ),(
          (Exists => False),
          (True, Dwarf, Gold ),
          (Exists => False),
          (True, Dwarf, Gold ),
          (Exists => False),
          (True, Dwarf, Gold ),
          (Exists => False),
          (True, Dwarf, Gold ),
          (Exists => False),
          (True, Dwarf, Gold ),
          (Exists => False),
          (True, Dwarf, Gold )
         ),(
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False),
            (Exists => False)
           ),(
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False),
              (Exists => False)
             ),(
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False),
                (Exists => False)
               ),(
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False),
                  (Exists => False)
                 ),(
                    (Exists => False),
                    (True, Dwarf, Scarlet ),
                    (Exists => False),
                    (True, Dwarf, Scarlet ),
                    (Exists => False),
                    (True, Dwarf, Scarlet ),
                    (Exists => False),
                    (True, Dwarf, Scarlet ),
                    (Exists => False),
                    (True, Dwarf, Scarlet ),
                    (Exists => False),
                    (True, Dwarf, Scarlet )
                   ),(
                      (Exists => False),
                      (Exists => False),
                      (True, Basilisk, Scarlet ),
                      (Exists => False),
                      (Exists => False),
                      (Exists => False),
                      (True, Elemental, Scarlet ),
                      (Exists => False),
                      (Exists => False),
                      (Exists => False),
                      (True, Basilisk, Scarlet ),
                      (Exists => False)
                     ))
     );
end Board_Types;

*** drgnchss.adb
with Board_Types; use Board_Types;
with Print_Board;

procedure Drgnchss is
   B: Board := Initial_Board;

begin
   Print_Board (B);
   return;
end Drgnchss;


*** print_board.adb
with Board_Types; use Board_Types;
with Ada.Text_Io; use Ada.Text_IO;

procedure Print_Board (B : Board) is

   function Piece_Char (Bp : Board_Piece) return Character is
   begin
      if Bp.Exists then
         return ('*');
      else
         return ('-');
      end if;
   end Piece_Char;

begin

      for J in Row_Type loop
         for K in Column_Type loop 
            Put (Piece_Char (B (Lower) (J, K)));
         end loop; -- Columns
         New_Line;
      end loop; -- Rows
   
end Print_Board;


-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux dvdeug 2.4.21dvdeug2 #1 Sat Jun 28 22:56:58 PDT 2003 i686
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (ignored: LC_ALL set)

Versions of packages gnat-3.3 depends on:
hi  gcc-3.3                    1:3.3.3-0pre1 The GNU C compiler
hi  gcc-3.3-base               1:3.3.3-0pre1 The GNU Compiler Collection (base 
ii  libc6                      2.3.2.ds1-10  GNU C Library: Shared libraries an

-- no debconf information




Reply to: