This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ada/25782] New: Garbage string returned from function call chain with mixture of constrained and unconstrained return types
- From: "holmana at adsmr dot co dot za" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Jan 2006 15:05:10 -0000
- Subject: [Bug ada/25782] New: Garbage string returned from function call chain with mixture of constrained and unconstrained return types
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Using gcc 4.0.2, with gcc -v giving:
----------------------------------------
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../src/configure --disable-nls --enable-languages=c,ada
--prefix=/disc/gbcc/home/allan/play/koala/gcc4/native1 --enable-libada
Thread model: posix
gcc version 4.0.2
----------------------------------------
and compiling the following code:
----------------------------------------
With Text_Io;
procedure testbugmain is
subtype IntermediateStringType is String(1..12);
Strings : Array(Boolean) of IntermediateStringType :=
("0123456789ab","ba9876543210");
Function translatePhrase(phraseToTranslate : in String) return String is
begin
return phraseToTranslate;
end;
Function intermediateString(flag : in Boolean) return
IntermediateStringType is
begin
declare
returnString : constant String := translatePhrase(Strings(flag));
begin
null;
-- Return A
-- return returnString;
end;
-- Return B
return translatePhrase(Strings(flag));
end;
begin
Text_Io.put_line("<" & intermediateString(TRUE) & ">");
Text_Io.put_line("<" & intermediateString(FALSE) & ">");
end testbugmain;
--------------------------------------------------------------
with compile command line and results:
------------------------------------------------------------
gnatmake -gnatf -gnatv -gnatVa -gnatwa testbugmain.adb
gcc -c -gnatf -gnatv -gnatVa -gnatwa testbugmain.adb
GNAT 4.0.2
Copyright 1992-2005 Free Software Foundation, Inc.
Compiling: testbugmain.adb (source file time stamp: 2006-01-13 14:16:28)
6. Strings : Array(Boolean) of IntermediateStringType :=
("0123456789ab","ba9876543210");
|
>>> warning: "Strings" is not modified, could be declared constant
18. returnString : constant String :=
translatePhrase(Strings(flag));
|
>>> warning: constant "returnString" is not referenced
34 lines: No errors, 2 warnings
gnatbind -x testbugmain.ali
gnatlink testbugmain.ali
-----------------------------------------------------------------------
Expected Behaviour:
Two lines should be printed, each containing the corresponding string from the
Strings array.
Actual Behaviour:
A run of the resulting executable prints out garbage. Specifically, the value
returned from the intermediateString function does not match the string looked
up in the Strings array; rather, the byte values seem as if they might be two
pointers.
If the return statement just after the "Return A" comment is uncommented, then
the code works as expected: The values looked up in the Strings array are
printed out.
--
Summary: Garbage string returned from function call chain with
mixture of constrained and unconstrained return types
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: holmana at adsmr dot co dot za
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25782