public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object
@ 2013-08-28 16:10 hans.buhrer at lmco dot com
2013-08-30 14:31 ` [Bug ada/58264] " ebotcazou at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: hans.buhrer at lmco dot com @ 2013-08-28 16:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
Bug ID: 58264
Summary: Incorrect 'First when assigning function-call.all (of
access String;) to an indefinite String object
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: hans.buhrer at lmco dot com
Created attachment 30713
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30713&action=edit
Minimal Ada source to reproduce the problem
In the source below, the function Peek returns a pointer to a
(formally)unconstrained String. The actual lower bound of the dynamically
allocated String object is 1.
When Peek.all is assigned to an indefinite String variable, the dope vector is
apparently not copied, but the dynamically allocated dope vector is reused.
When the dynamically allocated object is then Free'd (including its dope
vector) the 'First of the indefinite string object turns to garbage (0).
This only seems to happen for pointer-to-String that are returned by a function
call.
----------
with Ada.Text_Io;
with Ada.Unchecked_Deallocation;
procedure Failure is
type String_Ptr_T is access String;
procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr_T);
String_Data : String_Ptr_T := new String'("Hello World");
function Peek return String_Ptr_T is
begin
return String_Data;
end Peek;
begin
declare
Corrupted_String : String := Peek.all; -- Fails
-- Corrupted_String : String := String_Data.all; -- Works
begin
Ada.Text_Io.Put_Line(Integer'Image(Corrupted_String'First));
Free(String_Data);
Ada.Text_Io.Put_Line(Integer'Image(Corrupted_String'First));
end;
end Failure;
----------
elvm1>gnatmake -O0 -g failure.adb -cargs -v -save-temps -Wall -Wextra
gcc-4.6 -c -O0 -g -v -save-temps -Wall -Wextra failure.adb
Using built-in specs.
COLLECT_GCC=/usr//bin/gcc-4.6
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
COLLECT_GCC_OPTIONS='-gnatea' '-c' '-O0' '-g' '-v' '-save-temps' '-Wall'
'-Wextra' '-gnatez' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-linux-gnu/4.6/gnat1 -gnatwa -quiet -dumpbase failure.adb
-auxbase failure -O0 -Wall -Wextra -gnatez -gnatea -g -gnatez -mtune=generic
-march=i686 failure.adb -o failure.s
failure.adb:16:05: warning: "Corrupted_String" is not modified, could be
declared constant
COLLECT_GCC_OPTIONS='-gnatea' '-c' '-O0' '-g' '-v' '-save-temps' '-Wall'
'-Wextra' '-gnatez' '-mtune=generic' '-march=i686'
as --32 -o failure.o failure.s
COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-gnatea' '-c' '-O0' '-g' '-v' '-save-temps' '-Wall'
'-Wextra' '-gnatez' '-mtune=generic' '-march=i686'
gnatbind -x failure.ali
gnatlink failure.ali -O0 -g
elvm1>./failure
1
0
As a work around, using
Corrupted_String : String := Peek.all & "";
helps.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ada/58264] Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
@ 2013-08-30 14:31 ` ebotcazou at gcc dot gnu.org
2013-09-18 10:39 ` [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result ebotcazou at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-08-30 14:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-08-30
CC| |ebotcazou at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Thanks for reporting the problem.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
2013-08-30 14:31 ` [Bug ada/58264] " ebotcazou at gcc dot gnu.org
@ 2013-09-18 10:39 ` ebotcazou at gcc dot gnu.org
2013-09-18 10:51 ` ebotcazou at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-09-18 10:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |ebotcazou at gcc dot gnu.org
Summary|Incorrect 'First when |incorrect bounds of string
|assigning function-call.all |when assigned from
|(of access String;) to an |dereference of function
|indefinite String object |result
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
2013-08-30 14:31 ` [Bug ada/58264] " ebotcazou at gcc dot gnu.org
2013-09-18 10:39 ` [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result ebotcazou at gcc dot gnu.org
@ 2013-09-18 10:51 ` ebotcazou at gcc dot gnu.org
2013-09-18 10:55 ` ebotcazou at gcc dot gnu.org
2013-09-18 11:01 ` ebotcazou at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-09-18 10:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Author: ebotcazou
Date: Wed Sep 18 10:51:43 2013
New Revision: 202694
URL: http://gcc.gnu.org/viewcvs?rev=202694&root=gcc&view=rev
Log:
PR ada/58264
* gcc-interface/trans.c (Attribute_to_gnu): Define GNAT_PREFIX local
variable and use it throughout.
<Attr_Length>: Note whether the prefix is the dereference of a pointer
to unconstrained array and, in this case, capture the result for both
Attr_First and Attr_Last.
Added:
trunk/gcc/testsuite/gnat.dg/array_bounds_test2.adb
Modified:
trunk/gcc/ada/ChangeLog
trunk/gcc/ada/gcc-interface/trans.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
` (2 preceding siblings ...)
2013-09-18 10:51 ` ebotcazou at gcc dot gnu.org
@ 2013-09-18 10:55 ` ebotcazou at gcc dot gnu.org
2013-09-18 11:01 ` ebotcazou at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-09-18 10:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Author: ebotcazou
Date: Wed Sep 18 10:55:36 2013
New Revision: 202695
URL: http://gcc.gnu.org/viewcvs?rev=202695&root=gcc&view=rev
Log:
PR ada/58264
* gcc-interface/trans.c (Attribute_to_gnu): Define GNAT_PREFIX local
variable and use it throughout.
<Attr_Length>: Note whether the prefix is the dereference of a pointer
to unconstrained array and, in this case, capture the result for both
Attr_First and Attr_Last.
Added:
branches/gcc-4_8-branch/gcc/testsuite/gnat.dg/array_bounds_test2.adb
- copied unchanged from r202694,
trunk/gcc/testsuite/gnat.dg/array_bounds_test2.adb
Modified:
branches/gcc-4_8-branch/gcc/ada/ChangeLog
branches/gcc-4_8-branch/gcc/ada/gcc-interface/trans.c
branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
` (3 preceding siblings ...)
2013-09-18 10:55 ` ebotcazou at gcc dot gnu.org
@ 2013-09-18 11:01 ` ebotcazou at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-09-18 11:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58264
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |4.8.2
--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Fixed in 4.8.x and later.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-09-18 11:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-28 16:10 [Bug ada/58264] New: Incorrect 'First when assigning function-call.all (of access String;) to an indefinite String object hans.buhrer at lmco dot com
2013-08-30 14:31 ` [Bug ada/58264] " ebotcazou at gcc dot gnu.org
2013-09-18 10:39 ` [Bug ada/58264] incorrect bounds of string when assigned from dereference of function result ebotcazou at gcc dot gnu.org
2013-09-18 10:51 ` ebotcazou at gcc dot gnu.org
2013-09-18 10:55 ` ebotcazou at gcc dot gnu.org
2013-09-18 11:01 ` ebotcazou at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).