wavebitscientific / datetime-fortran

Date and time manipulation for modern Fortran
MIT License
137 stars 51 forks source link

Very strange (possibly compiler) bug with date2num #51

Closed nichannah closed 4 years ago

nichannah commented 6 years ago

The patch below introduces one passing and one failing test. This problem occurred with intel 17 but not 15, 16 or 18. It did not happen with gfortran.

diff --git a/src/tests/datetime_tests.f90 b/src/tests/datetime_tests.f90
index 0abb98d..799fadb 100644
--- a/src/tests/datetime_tests.f90
+++ b/src/tests/datetime_tests.f90
@@ -1026,6 +1026,16 @@ SUBROUTINE test_datetime
                     'datetime % utc() == num2date(date2num(datetime)) (now)')
   n = n+1

+  a = datetime(1901,05,1)
+  tests(n) = assert(a == num2date(date2num(a)),&
+                    'datetime == num2date(date2num(datetime)) (weird bug passes)')
+  n = n+1
+
+  a = datetime(1901,05,1,3)
+  tests(n) = assert(a == num2date(date2num(a)),&
+                    'datetime == num2date(date2num(datetime)) (weird bug fails)')
+  n = n+1
+
   ! Test for overflowing month
   a = datetime(2014,11,30,1)
   tests(n) = assert(a == num2date(date2num(a)),&

Intel 14 gives a compiler error

Scanning dependencies of target datetime_tests
[ 88%] Building Fortran object CMakeFiles/datetime_tests.dir/src/tests/datetime_tests.f90.o
/home/599/nah599/more_home/Download/datetime-fortran/src/tests/datetime_tests.f90(1): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for /home/599/nah599/more_home/Download/datetime-fortran/src/tests/datetime_tests.f90 (code 1)
make[2]: *** [CMakeFiles/datetime_tests.dir/src/tests/datetime_tests.f90.o] Error 1
make[1]: *** [CMakeFiles/datetime_tests.dir/all] Error 2
make: *** [all] Error 2

Intel 13 gives a segmentation fault:

test datetime == num2date(date2num(datetime)) (weird bug passes) : PASS
test datetime == num2date(date2num(datetime)) (weird bug fails)  : PASS
test datetime == num2date(date2num(datetime)) (overflowing month): PASS
test datetime == num2date(date2num(datetime)) (overflowing year) : PASS
-----------------------------------------------------------------------
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source
datetime_tests     0000000000452820  mod_datetime_mp_e         998  mod_datetime.f90
datetime_tests     000000000043D63D  datetime_tests_mp        1066  datetime_tests.f90
datetime_tests     0000000000448916  MAIN__                   1284  datetime_tests.f90
datetime_tests     000000000040300C  Unknown               Unknown  Unknown
libc.so.6          00002B896DBB1D1D  Unknown               Unknown  Unknown
datetime_tests     0000000000402F09  Unknown               Unknown  Unknown
milancurcic commented 6 years ago

Good catch and I agree, very strange bug. I only have ifort 18 with me right now and both test pass as expected. Maybe filing this on the Intel forums would be a good idea if this issue becomes a showstopper for you?

milancurcic commented 6 years ago

date2num and num2date use real64 from iso_fortran_env for some literal constants, I'm wondering if its implementation varies between these versions of ifort.

nichannah commented 4 years ago

I'm no longer able to reproduce this error with out latest compiler versions:

intel-compiler/2019.5.281 intel-compiler/2020.0.166