https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122863

--- Comment #2 from anlauf at gcc dot gnu.org ---
The code seems to work at first sight on x86_64.

But I can get it crash when compiling with -m32:

% gfc-16 pr122863.f90 -m32 -g && ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0xf7a1c11d in ???
#1  0xf7a1b1fd in ???
#2  0xf7ef058f in ???
#3  0x8048711 in __testmod_MOD___copy_INTEGER_4_
        at /home/anlauf/gcc-bugs/pr122863.f90:36
#4  0x8049225 in test
        at /home/anlauf/gcc-bugs/pr122863.f90:45
#5  0x8049371 in main
        at /home/anlauf/gcc-bugs/pr122863.f90:40

When compiling with -m64 -O0 -g and running under valgrind:

% valgrind --leak-check=full --track-origins=yes ./a.out 
==9673== Memcheck, a memory error detector
==9673== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==9673== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==9673== Command: ./a.out
==9673== 
==9673== Conditional jump or move depends on uninitialised value(s)
==9673==    at 0x401616: MAIN__ (pr122863.f90:45)
==9673==    by 0x4018EC: main (pr122863.f90:40)
==9673==  Uninitialised value was created by a stack allocation
==9673==    at 0x4013A8: MAIN__ (pr122863.f90:39)
==9673== 
==9673== Conditional jump or move depends on uninitialised value(s)
==9673==    at 0x40165E: MAIN__ (pr122863.f90:45)
==9673==    by 0x4018EC: main (pr122863.f90:40)
==9673==  Uninitialised value was created by a stack allocation
==9673==    at 0x4013A8: MAIN__ (pr122863.f90:39)
==9673== 
 Value of first item:
          42
==9673== 
==9673== HEAP SUMMARY:
==9673==     in use at exit: 8 bytes in 2 blocks
==9673==   total heap usage: 19 allocs, 17 frees, 5,452 bytes allocated
==9673== 
==9673== 4 bytes in 1 blocks are definitely lost in loss record 2 of 2
==9673==    at 0x4841984: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9673==    by 0x401471: MAIN__ (pr122863.f90:45)
==9673==    by 0x4018EC: main (pr122863.f90:40)
==9673== 
==9673== LEAK SUMMARY:
==9673==    definitely lost: 4 bytes in 1 blocks
==9673==    indirectly lost: 0 bytes in 0 blocks
==9673==      possibly lost: 0 bytes in 0 blocks
==9673==    still reachable: 4 bytes in 1 blocks
==9673==         suppressed: 0 bytes in 0 blocks
==9673== Reachable blocks (those to which a pointer was found) are not shown.
==9673== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9673== 
==9673== For lists of detected and suppressed errors, rerun with: -s
==9673== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

No issue when compiling with -O1 or higher.
There must be something fishy that can get optimized out.

Reply via email to