https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125044
Bug ID: 125044
Summary: taszk declared as a class-wide object on the stack:
not starting. works without 'Class
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: 00120260a at gmail dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
Here is the code:
pragma Ada_2022;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main2 is
package Circuits is
type BoolArray is array (Positive range <>) of Boolean with
Pack;
function FnNot (Arr: BoolArray) return Boolean is (not Arr(1));
function FnOr (Arr: BoolArray) return Boolean is (Arr(1) or
Arr(2));
function FnXOr (Arr: BoolArray) return Boolean is (Arr(1) xor
Arr(2));
function FnAnd (Arr: BoolArray) return Boolean is (Arr(1) and
Arr(2));
function FnNor (Arr: BoolArray) return Boolean is (not Arr(1)
and not Arr(2));
type GateType is task interface;
procedure Enter (T: GateType; V: Boolean) is abstract;
type Circuit is array (Positive range <>) of access constant
GateType'Class;
task type Gates
(Nentries: Positive;
Func: access function (A: BoolArray) return Boolean;
OutputCircuit: access constant Circuit; Size: Positive)
is new GateType with
entry Enter (V: Boolean);
end Gates;
task type EndGate (Size: Positive) is new GateType with
entry Enter (V: Boolean);
entry GiveResult (R: out BoolArray);
end EndGate;
function MakeGate
(Nentries: Positive;
Func: access function (A: BoolArray) return Boolean;
OutputCircuit: access constant Circuit; Size: Positive)
return Gates'Class;
end Circuits;
package body Circuits is
task body Gates is
InputArray: BoolArray (1..Nentries);
begin
for S in 1..Size loop
for A of InputArray loop
accept Enter (V: Boolean) do
A := V;
end Enter;
if InputArray'Length = 1 then
Put_line ("arrived at ""not"":
" & A'Image);
end if;
end loop;
for A of OutputCircuit.all loop
A.Enter(Func(InputArray));
end loop;
end loop;
end Gates;
task body EndGate is
Result: BoolArray (1..Size);
begin
for A of Result loop
accept Enter (V: Boolean) do
A := V;
end Enter;
end loop;
accept GiveResult (R: out BoolArray) do
R := Result;
end GiveResult;
end EndGate;
function MakeGate
(Nentries: Positive;
Func: access function (A: BoolArray) return Boolean;
OutputCircuit: access constant Circuit;
Size: Positive) return Gates'Class is
begin
return G: Gates (Nentries, Func,OutputCircuit,Size);
end MakeGate;
end Circuits;
use Circuits;
theEnd: aliased EndGate (1);
NotGate: aliased Gates (1, FnNot'Access, new Circuit'([theEnd'Access]),
1);
XorGate: aliased Gates'Class := MakeGate(2, FnXor'Access, new
Circuit'([NotGate'Access]), 1); -- HERE
OrGate: aliased Gates (2, FnOr'Access, new Circuit'([XorGate'Access]),
1);
theTable : BoolArray (1..1);
begin
OrGate.Enter(False);
OrGate.Enter(True);
XorGate.Enter(True);
theEnd.GiveResult (theTable);
Put_line(theTable'Image);
end Main2;
The line marked by "HERE" cause the relevant task to shut down immediately, and
attempts to do a rendezvous with it propagates Tasking_Error.
Replacing it with
XorGate: aliased Gates(2, FnXor'Access, new Circuit'([NotGate'Access]), 1);
solves it.
Linux 84-47-09-37-40-34 6.12.74+deb13+1-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.12.74-2 (2026-03-08) x86_64 GNU/Linux
Using built-in specs.
COLLECT_AS_OPTIONS='--version'
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/drm/.dotfiles/.local/share/alire/toolchains/gnat_native_15.2.1_4640d4
b3/bin/../libexec/gcc/x86_64-pc-linux-gnu/15.2.0/lto-wrapper
gcc (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
COLLECT_GCC_OPTIONS='-v' '--version' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a.'
Linux 84-47-09-37-40-34 6.12.74+deb13+1-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.12.74-2 (2026-03-08) x86_64 GNU/Linux
parameters give to gcc:
gcc -c main2.adb
gnatbind -x main2.ali
gnatlink main2.ali