Skip to content

[flang] Issue with save-temps and labels in certain columns and long procedure names #184802

@mathomp4

Description

@mathomp4

Summary

In testing some code with Flang 22, I encountered an issue with -save-temps. Well, first I found #119624 (fixing #58587) telling me I had to also add -fno-integrated-as to use it. But after that, the compiler kept randomly failing on valid Fortran.

Essentially, when compiling free-form Fortran code with flang, enabling -save-temps (or -save-temps=obj / -save-temps=cwd) can cause an indented statement label to be lost depending on the number of spaces in the indent, producing:

error: Label '101' was not found

The same source compiles successfully without -save-temps.


Compiler Version

> flang --version
flang version 22.1.0 (git@github.com:GEOS-ESM/build-llvm-flang.git 337c2cab67836c0beb2910664cf02d1df1e27609)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gpfsm/dnb10/projects/p50/comp/SLES-15/llvm-flang/22.1.0/bin

Minimal Reproducer

write(*, fmt=101) 12
    101 format(i0)
end

Note that the label 101 is indented (four leading spaces), which is valid in free-form Fortran.


Commands

Baseline (works):

flang -O0 -g -c repro.F90

With -save-temps (fails):

flang -O0 -g -fno-integrated-as -save-temps -c repro.F90

Error:

> flang -O0 -g -fno-integrated-as -save-temps repro.F90
error: Semantic errors in repro.i
./repro.F90:1:7: error: Label '101' was not found
        write(*, fmt=101) 12
        ^^^^^^^^^^^^^^^^^^^^

Additional Observations

The failure depends on the indentation of the statement label. Using a small script (see https://gist.github.com/mathomp4/b073a15ca4eaea4bdcc0cad00266cadb) to generate different indent levels produced the following results:

> ./run_indent_matrix.sh
spaces | label_col  | rc   | result
-------+------------+------+------------------------------
0      | 1          | 0    | OK
1      | 2          | 0    | OK
2      | 3          | 0    | OK
3      | 4          | 1    | FAIL: label 101 not found
4      | 5          | 1    | FAIL: label 101 not found
5      | 6          | 1    | FAIL: error: Could not parse obj/repro_indent_5.i
6      | 7          | 0    | OK
7      | 8          | 0    | OK
8      | 9          | 0    | OK

Wrote:
  Sources/logs: obj/repro_indent_*.F90 / .log
  Table TSV:    obj/results.tsv

Metadata

Metadata

Assignees

Labels

flangFlang issues not falling into any other category

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions