llvm / llvm/llvm-project

[Flang] Compilation results in bogus movabsq instruction

Open
#161,568 4 comments 0 reactions 0 assignees View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I'm compiling the https://github.com/jacobwilliams/json-fortran/releases/tag/9.0.2 project with Flang 21.1.1

The compilation is successful, however running `make test` results in many tests crashing with SIGSEGV. Here's the backtrace for one of them:

```
Process 44846 stopped
* thread #1, name = 'jf_test_03', stop reason = signal SIGSEGV: invalid permissions for mapped object (fault address: 0x820d28cb0)
frame #0: 0x0000000820d28cb0
-> 0x820d28cb0: movabsq $0x8226946d0, %r11 ; imm = 0x8226946D0
0x820d28cba: movabsq $0x820d28c98, %r10 ; imm = 0x820D28C98
0x820d28cc4: jmpq *%r11
0x820d28cc7: addb %dh, 0x820d28e(%rax)
(lldb) bt
* thread #1, name = 'jf_test_03', stop reason = signal SIGSEGV: invalid permissions for mapped object (fault address: 0x820d28cb0)
* frame #0: 0x0000000820d28cb0
frame #1: 0x000000082269962d libjsonfortran.so.9.0`_QMjson_value_moduleFjson_traversePtraverse at json_value_module.F90:9590:9
frame #2: 0x000000082268c6f1 libjsonfortran.so.9.0`_QMjson_value_modulePjson_traverse at json_value_module.F90:9573:38
frame #3: 0x0000000822654831 libjsonfortran.so.9.0`_QMjson_value_modulePjson_check_all_for_duplicate_keys at json_value_module.F90:5823:9
frame #4: 0x00000008226740d7 libjsonfortran.so.9.0`_QMjson_value_modulePjson_parse_file at json_value_module.F90:9815:17
frame #5: 0x000000082269f276 libjsonfortran.so.9.0`_QMjson_file_modulePjson_file_load at json_file_module.F90:871:5
frame #6: 0x00000000002148e1 jf_test_03`_QMjf_test_3_modPtest_3 at jf_test_03.F90:57:5
frame #7: 0x0000000000215f11 jf_test_03`_QQmain at jf_test_03.F90:155:5
frame #8: 0x0000000000215f42 jf_test_03`main at jf_test_03.F90:158:1
frame #9: 0x0000000824dfec3a libc.so.7`__libc_start1 + 298
frame #10: 0x00000000002142d0 jf_test_03`_start at crt1_s.S:83
```

The problem persists even when compiling with `-O0 -g`.

Contributor guide

Open the contributing guide

Research direction

Reproduce with Flang 21.1.1 by compiling json-fortran 9.0.2 and running `make test`, starting from the SIGSEGV in `json_value_module.F90` and the call path through `json_file_module.F90` and `jf_test_03.F90`. Compare the generated `movabsq` sequence under `-O0 -g`; done means the tests no longer crash and bogus instructions are absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.