<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/129456>129456</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compile error when when a statement label is specified in function statement
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang : 21.0.0(c8b40867d144395ad3c306a3cf87f970e0f97f07)/AArch64
```

When a `statement label` is specified in `function` statement, a compilation error occurs.  
The above program is `dwarf6c_2.f`.  
According to `Fortran Standard 2023: 6.2.5 Statement labels`, there is no problem with this program.  
When no `statement label` is specified in `function` statement, the compilation succeeds.  
The above program is `dwarf6c_3.f`.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

dwarf6c_2.f:
```fortran
 1    function fun()
 2    end function
 3    write(6,*) "pass"
 4    end
```

```
$ flang dwarf6c_2.f
error: Could not parse dwarf6c_2.f
./dwarf6c_2.f:1:21: error: expected '='
   1    function fun()
 ^
./dwarf6c_2.f:1:7: in the context: statement function definition
   1 function fun()
        ^
./dwarf6c_2.f:1:2: in the context: declaration construct
   1    function fun()
   ^
./dwarf6c_2.f:1:2: in the context: specification part
   1    function fun()
   ^
./dwarf6c_2.f:1:2: in the context: main program
   1    function fun()
   ^
./dwarf6c_2.f:2:11: error: expected end of statement
   2    end function
 ^
./dwarf6c_2.f:2:7: in the context: END PROGRAM statement
   2    end function
        ^
./dwarf6c_2.f:1:2: in the context: main program
   1 function fun()
   ^
$
```

```
$ gfortran dwarf6c_2.f; ./a.out
 pass
$
```

```
$ ifx ; dwarf6c_2.f./a.out
dwarf6c_2.f(1): warning #6178: The return value of this FUNCTION has not been defined.   [FUN]
 1 function fun()
---------------^
 pass
$
```

dwarf6c_3.f:
```fortran
 function fun()
 2    end function
 3    write(6,*) "pass"
 4 end
```

```
$ flang dwarf6c_3.f
./dwarf6c_3.f:1:16: warning: Function result is never defined
        function fun()
                 ^^^
 pass
$
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vt2O2zYTfRr6ZrACRerHuvCFYkfBd_FtijRpLwuaHFkMZNIgqfX27QtKsqNNvG6waAzDq-XPOTNHh8MR3uuDQdyQ_B3JdysxhM66je2MfWi_rvZW_b0hBZ2_tP4DndfWgG2h7YU5AOE1sDShCSVsLdf7jK6LUqVZxqtcKC45LQSX7bpsq5IibauypSVhFWFNXTvZFRmh9ZKB0PrPDg0IIAX1QQQ8ognQiz32pKCgPfgTSt1qVKBNXNUORgZtTZy-7iBsCwKkPZ50L-IsoHPWgZVycD4BILT-3CGIvX1CODl7cOIY0UlB1Vm4tpB_saQlBZ3W1lJap7Q5QLBxTWNdcMLA70EYJZwCRhmPahQJS_I4vIzcx-TYFkKHDiOLsZFz3-MRzjp0EDrtL1FMhKMKxv4HMoQOXwjhBykR1U-KwCcRplcTF7e27-05KiEcjuABfbjsjoRNtEZ8-NDOKgmjQLfPyzAIa_AZ5TCG5NAPfZhJlvLzeumPGY7QGlIAgEvK8YGwdfQVrYHFKTTqOh0HeRw8Ox2QsHVB2JawmrAKCGMn4T1hLK7K5q0_mvLFvyyb7b8Mldajw6IHtnboFRgb4CScx--WJYQ1L3NMCa9Z_IErBD6fUAZUQFhJ-C7-0hrgXt4kf_8qehkxtZm9YAI-hzjyzVlXSIWtNvoiWyS8zTZ_7pGy26QKZS_c5EVpjQ9ukOFfs3sT1XxG5ER2Eu4X8RyFNtcT8HaGiJ6-4oNoaNsuTvaIdNPr9-BfMcL7xx389unjh0_1_3-K4u1v_5ZU93Ui7MYl8f15PFxKzYtA3kGMTSR2GJMZT_pPAsZyFQEWeEusJQ1bpzFkXsNZOBMrI2G8SMt1HIol02EYnIEn0Q8YX-JY7Zsvj9vP__v4CJ3wY63YI87HD1UyZv-u-fJI8t1U726K9PDyMwl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