[Bug optimization/14863] [3.4/3.5 regression] unit-at-a-time causes miscompilation
rguenth at tat dot physik dot uni-tuebingen dot de
gcc-bugzilla@gcc.gnu.org
Wed Apr 7 13:26:00 GMT 2004
------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de 2004-04-07 13:26 -------
Subject: Re: [3.4/3.5 regression] unit-at-a-time
causes miscompilation
On Wed, 7 Apr 2004, pinskia at gcc dot gnu dot org wrote:
>
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-07 13:06 -------
> Here is the backtrace I get with the mainline at -O1 -g -funit-at-a-time --param large-function-
> insns=3000:
>
> #0 0x4207af5c in chunk_free () from /lib/i686/libc.so.6
> #1 0x4207acb4 in free () from /lib/i686/libc.so.6
> #2 0x400bf761 in operator delete (ptr=0x4212e0f0)
> at /home/gates/pinskia/src/gnu/gcc/src/libstdc++-v3/libsupc++/del_op.cc:39
> #3 0x0805faa3 in ~PatchSwapLayout (this=0xbffec080) at pr14863.cc:9943 <-- not right function
> name
> #4 0x080539ff in main (argc=1, argv=0xbffec194) at pr14863.cc:52762
>
>
>
> I think this is related to some pointer :
> char *tmp = new char[nsize];
> pBeginNew = reinterpret_cast<T *>(tmp);
>
>
> char *tmp = reinterpret_cast<char *>(pBegin_m);
> delete [] tmp; <--- crashing here
>
> I do not understand why the code is doing this though as you should be just using new T[newsize]
> instead. The other thing is that you could be over running the buffer which could cause this problem.
Yes, it looks a bit twisted, but I think the purpose of allocating and
deallocating char[] rather than T[] is to allow manual (default)
constructing the objects, or not, by using placement new to the individual
elements. This has been done for optimization purposes, I think, but I
may be wrong.
Is anything conceptually wrong with the following?
T *m = reinterpret_cast<T *>(new char[n*sizeof(T)]);
for (int i=0; i<n; ++i)
new (&m[i]) T;
for (int i=0; i<n; ++i)
m[i].~T();
delete [] reinterpret_cast<char *>(m);
if yes, there may be problems within the code. There is bounds checking
code available, so I'll check if we don't override some here.
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14863
More information about the Gcc-bugs
mailing list