Issue 129456
Summary [Flang] Compile error when when a statement label is specified in function statement
Labels flang:frontend
Assignees
Reporter ohno-fj
    ```
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
$
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to