From 7a80a882ab838b037ca7afc4c14e2a098ce07493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Sat, 1 Aug 2015 13:14:30 +0200 Subject: [PATCH] 2015-08-01 13:14 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/vm/asort.c * restored original loop and added different workaround which for the problem in 64 bit MinGW we exploited. It's dummy function call inside a loop so probably link time optimization (LTO is enabled by -O4 in the newest GCC versions) ignore it and the problem will reappear. Anyhow it only temporary solution which should give time to create self contain example and report the problem to MinGW authors - it's highly possible that also other code exploited this problem so be careful with MinGW64. % fixed index range checking to eliminate unnecessary index verification --- ChangeLog.txt | 12 ++++++++++++ src/vm/asort.c | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8a4e7712bf..fe81270daf 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,18 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-08-01 13:14 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/vm/asort.c + * restored original loop and added different workaround which for + the problem in 64 bit MinGW we exploited. It's dummy function call + inside a loop so probably link time optimization (LTO is enabled + by -O4 in the newest GCC versions) ignore it and the problem will + reappear. Anyhow it only temporary solution which should give time + to create self contain example and report the problem to MinGW + authors - it's highly possible that also other code exploited this + problem so be careful with MinGW64. + % fixed index range checking to eliminate unnecessary index verification + 2015-08-01 01:28 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/vm/asort.c * added workaround for bug in 64 bit MinGW builds diff --git a/src/vm/asort.c b/src/vm/asort.c index 00e4266941..2f7bd0db6a 100644 --- a/src/vm/asort.c +++ b/src/vm/asort.c @@ -280,9 +280,14 @@ static void hb_arraySortStart( PHB_BASEARRAY pBaseArray, PHB_ITEM pBlock, HB_SIZE * pBuffer, * pDest, * pPos, nPos, nTo; pBuffer = ( HB_SIZE * ) hb_xgrab( sizeof( HB_SIZE ) * 2 * nCount ); - nPos = nCount; - while( nPos-- ) + for( nPos = 0; nPos < nCount; ++nPos ) + { +#ifdef __MINGW64__ + /* added dummy function call to disable buggy optimization in MinGW64 */ + hb_gcDummyMark( NULL ); +#endif pBuffer[ nPos ] = nStart + nPos; + } if( hb_arraySortDO( pBaseArray, pBlock, pBuffer, &pBuffer[ nCount ], nCount ) ) pPos = ( pDest = pBuffer ) + nCount; @@ -290,7 +295,7 @@ static void hb_arraySortStart( PHB_BASEARRAY pBaseArray, PHB_ITEM pBlock, pDest = ( pPos = pBuffer ) + nCount; /* protection against array resizing by user codeblock */ - if( nStart + nCount >= pBaseArray->nLen ) + if( nStart + nCount > pBaseArray->nLen ) { if( pBaseArray->nLen > nStart ) {