digitalmars.D.bugs - Very strange bug causing Access Violation with -O and -release
- Deewiant (43/43) Aug 06 2005 DMD 0.128 on Windows XP SP2.
- =?ISO-8859-15?Q?Thomas_K=FChne?= (13/58) Aug 06 2005 -----BEGIN PGP SIGNED MESSAGE-----
- Walter (2/2) Aug 10 2005 You've found a bug in the optimizer. It'll get fixed in the next update.
DMD 0.128 on Windows XP SP2. -- void foo(inout real[] arr) { // i = 0 doesn't trigger the bug, everything bigger seems to // also, making this const fixes the bug size_t i = 1; for (size_t j = i; j >= i; j -= i) { // dummy line which fixes the bug goes here // it can be anything that accesses j in some way // such as any of: //size_t x = j; //printf("%d", j); //j = i; // interesting results follow from this: //printf("%d", i); // it prints a _lot_ of ones arr[j] = arr[j - i]; } } void main() { real[] array; array.length = 2; // whatever, as long as it's more than 1 foreach (inout real i; array) i = 1; // just something foo(array); } -- IMO this bug is strange because: It is only triggered if the array is of type cdouble, real, ireal, or creal. (FWIW, my machine's a 1.2 GHz Duron - reals on other CPUs might not trigger the bug?) The code must be compiled with both -release and -O to trigger the bug. What's explained in the comments... a dummy line accessing j inside the for loop fixes the bug, if i is const the bug is fixed, if you print i within the for loop you get _many_ of them. The number seems to depend on the type of the array (cdouble, real, ireal, creal) and on its length. The smallest number I got was 402 (creal, array length 2) and the largest was 1227 (real, array length 2).
Aug 06 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Deewiant schrieb:DMD 0.128 on Windows XP SP2. -- void foo(inout real[] arr) { // i = 0 doesn't trigger the bug, everything bigger seems to // also, making this const fixes the bug size_t i = 1; for (size_t j = i; j >= i; j -= i) { // dummy line which fixes the bug goes here // it can be anything that accesses j in some way // such as any of: //size_t x = j; //printf("%d", j); //j = i; // interesting results follow from this: //printf("%d", i); // it prints a _lot_ of ones arr[j] = arr[j - i]; } } void main() { real[] array; array.length = 2; // whatever, as long as it's more than 1 foreach (inout real i; array) i = 1; // just something foo(array); } -- IMO this bug is strange because: It is only triggered if the array is of type cdouble, real, ireal, or creal. (FWIW, my machine's a 1.2 GHz Duron - reals on other CPUs might not trigger the bug?) The code must be compiled with both -release and -O to trigger the bug. What's explained in the comments... a dummy line accessing j inside the for loop fixes the bug, if i is const the bug is fixed, if you print i within the for loop you get _many_ of them. The number seems to depend on the type of the array (cdouble, real, ireal, creal) and on its length. The smallest number I got was 402 (creal, array length 2) and the largest was 1227 (real, array length 2).Added to DStress as http://dstress.kuehne.cn/run/f/for_06_A.d ... http://dstress.kuehne.cn/run/f/for_06_R.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFC9N4x3w+/yD4P9tIRAiDFAJ0TfLvRewo2CsW3pnsPQPze1b0iqQCghclO O0/cmObBKYVh7U5P7YJrW2k= =iEYh -----END PGP SIGNATURE-----
Aug 06 2005
You've found a bug in the optimizer. It'll get fixed in the next update. Thanks, -Walter
Aug 10 2005