Hi Pascal,
thank you for your reply.
I’ll give you a complete overview.
I inherited some CW for ColdFire projects from a colleague who left Jetter few years ago. He started with v6.4 and tried to switch to v7.2.1, but found that the new compiler was buggy. We set back to v6.4 but used the v7.2.1 C lib (EWL) as a subproject, because of the much better performance (especially of the string part). That works fine in different projects for years.
I now have to integrate code from another company written in C+. So I added the source code of the C+ lib of v7.2.1 as a subproject, too. But I got problems with “delete []” (new/new[]/delete/delete[] are widely-used in the new code). In some parts the compiler seems to generate wrong code. The following examples are copies of the debugger window in “Mixed Mode”.
Used macro:
#define SafeDeleteArray(p) {if (EC_NULL!=(p)) {delete [] (p); (p) = EC_NULL;}}
Example for correct compilation: pData is a pointer to ‘unsigned char’.
if (pData != EC_NULL)
40165032: 206EFFA0 movea.l -96(a6),a0
40165036: 4A88 tst.l a0
40165038: 670A beq.s CEcConfigXpat::CfgCreateECatMbxCoeCmd+0x184 (0x40165044); 0x40165044
{
SafeDeleteArray(pData);
4016503A: 4A88 tst.l a0
4016503C: 6706 beq.s CEcConfigXpat::CfgCreateECatMbxCoeCmd+0x184 (0x40165044); 0x40165044
4016503E: 4EB94011EAB0 jsr operator delete[] (0x4011eab0); 0x4011eab0
}
Example for incorrect compilation: pMasterDesc is a pointer to ‘struct’.
if( pMasterDesc != EC_NULL )
401749EC: 4A8C tst.l a4
401749EE: 6712 beq.s CEcDeviceFactory::DeviceFactoryCreateMaster+0x162 (0x40174a02); 0x40174a02
{
SafeDeleteArray(pMasterDesc);
401749F0: 4A8C tst.l a4
401749F2: 670E beq.s CEcDeviceFactory::DeviceFactoryCreateMaster+0x162 (0x40174a02); 0x40174a02
401749F4: 4A8C tst.l a4
401749F6: 670A beq.s CEcDeviceFactory::DeviceFactoryCreateMaster+0x162 (0x40174a02); 0x40174a02
401749F8: 41ECFFF8 lea -8(a4),a0
401749FC: 4EB94011EAB0 jsr operator delete[] (0x4011eab0); 0x4011eab0
}
There’s no source for the commands at addresses 401749f4/401749f6/401749f8. Minus 8 at address 401749f8 leads to an exception. It doesn’t matter if ‘operator delete[]’ calls ‘free’ of the C lib or ‘free’ of our RTOS.
If you will confirm that this is a compiler problem of v6.4 and v10.x compiler does not have such problems, we have to move to v10.x. Ok, then we’ll get problems with the project’s schedule, but there might be no other solution.
Best regards,
by order of Stefan Kaiser
Embedded Systems
Jetter AG
Gräterstraße 2
D-71642 Ludwigsburg
tel. +49 7141 2550-441
fax. +49 7141 2550-425
mailto:skaiser@jetter.de
http://www.jetter.de/
VAT Reg. - No.: DE 812 643 615
Registered: Stuttgart HRB 205545
CEO: Martin Jetter
Board of Directors: Christian Benz, Günter Eckert
Chairman of the Supervisory Board: Dr. Michael Oltmanns
Subscribe now to our internet newsletter at:
http://www.jetter.de/820.0.html
Von: Pascal Irrle
Gesendet: Dienstag, 6. August 2013 14:36
An: Kaiser, Stefan
Betreff: Re: - Problem with CodeWarrior 6.4 and C++ (new/delete)
<https://community.freescale.com/>
Problem with CodeWarrior 6.4 and C++ (new/delete)
reply from Pascal Irrle<https://community.freescale.com/people/trytohelp?et=watches.email.thread> in Classic/Legacy CodeWarrior - View the full discussion<https://community.freescale.com/message/343472?et=watches.email.thread#343472>