llvm / llvm/llvm-project

[Flang] Spurious errors for common blocks with binding labels

Open
#212,682 2 comments 0 reactions 1 assignee Claimed by @mrbahrani View on GitHub
flang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

According to the Fortran 2023 standard, entities with binding labels are global identifiers, but common blocks with binding labels are local identifiers. However, Flang also seems to treat the latter as global identifiers.

* 18.9.1 General

> If a common block is specified in a BIND statement, it shall be specified in a BIND statement with the same binding label in each scoping unit in which it is declared.

* 19.2 Global identifiers

> Program units, common blocks, external procedures, entities with binding labels, external input/output units, pending data transfer operations, and images are global entities of a program. The name of a common block with no binding label, external procedure with no binding label, or program unit that is not a submodule is a global identifier.

* 19.3.1 Classes of local identifiers

> Identifiers of entities, other than statement or construct entities (19.4), in the classes
>
> 1. named variables, named constants, named procedure pointers, named constructs, statement functions, internal procedures, module procedures, dummy procedures, intrinsic procedures, external procedures that have binding labels, intrinsic modules, abstract interfaces, generic interfaces, nonintrinsic types, namelist groups, external procedures accessed via USE, and statement labels,
> 2. type parameters, components, and type-bound procedure bindings, in a separate class for each type,
> 3. argument keywords, in a separate class for each procedure with an explicit interface, and
> 4. common blocks that have binding labels
>
> are local identifiers.

### Reproducer

* test.f90

```fortran
subroutine sub
integer :: iii
common /a/ iii
bind(c,name="com") :: /a/
if (iii/=100) print *,'fail'
end

program main
integer :: iii
common /b/ iii
bind(c,name="com") :: /b/
iii=100
call sub
print *,'pass'
end
```

* commands

```console
$ flang --version
flang version 24.0.0git (https://github.com/llvm/llvm-project.git 4068f4d2e0f30626e2f0fdf716e62624519bdd5e)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 && ./a.out
error: Semantic errors in test.f90
test.f90:10:11: error: Two entities have the same global name 'com'
common /b/ iii
^
test.f90:3:11: Conflicting declaration
common /a/ iii
^
```

## Other Compilers

* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran test.f90 && ./a.out
pass
```

* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.

$ ifx -O0 test.f90 && ./a.out
pass
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.