Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: string_intrinsic (move) failed built with GCC 13.2 #731

Closed
band-a-prend opened this issue Aug 18, 2023 · 3 comments · Fixed by #736
Closed

Test: string_intrinsic (move) failed built with GCC 13.2 #731

band-a-prend opened this issue Aug 18, 2023 · 3 comments · Fixed by #736
Labels
bug Something isn't working

Comments

@band-a-prend
Copy link

band-a-prend commented Aug 18, 2023

Description

If Fortran stdlib build with GCC 13.2 when on running test the string_intrinsic test fail with error (debug mode):

38/52 Test: string_intrinsic
Command: "/var/tmp/portage/dev-libs/fortran-stdlib-0.2.1-r1/work/stdlib-0.2.1_build/src/tests/string/test_string_intrinsic" "/var/tmp/portage/dev-libs/fortran-stdlib-0.2.1-r1/work/stdlib-0.2.1_build/src/tests/string"
Directory: /var/tmp/portage/dev-libs/fortran-stdlib-0.2.1-r1/work/stdlib-0.2.1/src/tests/string
"string_intrinsic" start time: Jul 23 19:27 MSK
Output:
----------------------------------------------------------
# Testing: string-intrinsic
  Starting lgt ... (1/17)
       ... lgt [PASSED]
  Starting llt ... (2/17)
       ... llt [PASSED]
  Starting lge ... (3/17)
       ... lge [PASSED]
  Starting lle ... (4/17)
       ... lle [PASSED]
  Starting trim ... (5/17)
       ... trim [PASSED]
  Starting len ... (6/17)
       ... len [PASSED]
  Starting len_trim ... (7/17)
       ... len_trim [PASSED]
  Starting adjustl ... (8/17)
       ... adjustl [PASSED]
  Starting adjustr ... (9/17)
       ... adjustr [PASSED]
  Starting scan ... (10/17)
       ... scan [PASSED]
  Starting verify ... (11/17)
       ... verify [PASSED]
  Starting repeat ... (12/17)
       ... repeat [PASSED]
  Starting index ... (13/17)
       ... index [PASSED]
  Starting char ... (14/17)
       ... char [PASSED]
  Starting ichar ... (15/17)
       ... ichar [PASSED]
  Starting iachar ... (16/17)
       ... iachar [PASSED]
  Starting move ... (17/17)

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

Backtrace for this error:
#0  0x7fe30b93f8e8 in ???
#1  0x7fe30b93ea3d in ???
#2  0x7fe30b67b98f in ???
#3  0x7fe30b6e24fd in ???
#4  0x7fe30bbe85df in make_output
	at /var/tmp/portage/dev-util/fortran-test-drive-0.4.0/work/test-drive-0.4.0/src/testdrive.F90:459
#5  0x7fe30bbe85df in run_unittest
	at /var/tmp/portage/dev-util/fortran-test-drive-0.4.0/work/test-drive-0.4.0/src/testdrive.F90:424
#6  0x7fe30bbef984 in __testdrive_MOD_run_testsuite
	at /var/tmp/portage/dev-util/fortran-test-drive-0.4.0/work/test-drive-0.4.0/src/testdrive.F90:336
#7  0x561ec26e6d70 in tester
	at /var/tmp/portage/dev-libs/fortran-stdlib-0.2.1-r1/work/stdlib-0.2.1/src/tests/string/test_string_intrinsic.f90:745
#8  0x561ec26e445e in main
	at /var/tmp/portage/dev-libs/fortran-stdlib-0.2.1-r1/work/stdlib-0.2.1/src/tests/string/test_string_intrinsic.f90:730
<end of output>
Test time =   0.01 sec
----------------------------------------------------------
Test Failed.

Actually it could be related to

call move(from_string, from_string)
because if simple test program

program test

    character(len=:), allocatable :: output
    character(len=:), allocatable :: input
    input = "Test sting"
!    output = "Test sting"
    print *, input
    call move_alloc(input, output)
    print *, output, "DONE1"

    call move_alloc(output, output)
    print *, output, "DONE2"
end program

is tried to compile with GCC 13.2 then the compile error is arrised

example.f90:11:28:

   11 |     call move_alloc(output, output)
      |                            1
Error: The FROM and TO arguments at (1) violate aliasing restrictions (F2003 12.4.1.7)

If compiled with GCC 12.x then there is no error with string_intrinsic test.

If comment the appropriate test (stdlib/test/string/test_string_intrinsic.f90:716-718) then string_intrinsic is passed

!        call move(from_string, from_string)
!        call check(error, from_string == "", "move: test_case 8")
!        if (allocated(error)) return

Expected Behaviour

All tests should be passed.

Version of stdlib

0.2.1, 0.3.0

Platform and Architecture

Gentoo Linux

Additional Information

The build and testing are made with Gentoo package manager to package Fortran stdlib for Gentoo Guru (maintained by users) repository.

Related issue: https://bugs.gentoo.org/910241

@band-a-prend band-a-prend added the bug Something isn't working label Aug 18, 2023
@jvdp1
Copy link
Member

jvdp1 commented Aug 19, 2023

Thank you for reporting this issue with a detailed explanation. It seems related to #726
I am not sure why people would aim to move mem from one variable to the same variable.

@awvwgk Any idea on how to solve this issue?Maybe by creating a temp variable?

@awvwgk
Copy link
Member

awvwgk commented Aug 20, 2023

The issue is that we declare the second argument of move as intent(out), the only way to work with this would change the second argument to intent(inout).

@band-a-prend
Copy link
Author

band-a-prend commented Aug 21, 2023

Is this string meant?

type(string_type), intent(out) :: to

I tried to replace it with

type(string_type), intent(inout) :: to

but without success for the mentioned test: it still fails with gcc 13.

What about additional check instead smth. like

if (from%raw .neqv. to%raw) call move_alloc(from%raw, to%raw)

Or smth. that check if from and to already use the same memory, e.g. via loc function?

But I need to check results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants