flang-compiler / flang

Flang is a Fortran language front-end designed for integration with LLVM.
Other
799 stars 134 forks source link

Construct names check misses inclusive scope rule #885

Open kiranchandramohan opened 4 years ago

kiranchandramohan commented 4 years ago

Also filed as https://github.com/flang-compiler/f18/issues/1103 in F18.

For the program given below (or a similar program where block with name lp replaced by do loops) flang does not detect the semantic error that a scope cannot have constructs with the same name.

program scope
  lp: block
  end block lp
  block
    lp: block
      if (k==20) exit lp
    end block lp
  end block
end program

Construct names are local identifiers and scope of local identifiers include the scopes in nested block constructs. And names cannot clash in the same scope. The relevant portion of Fortran 2018 standard given below.

19.3 Local identifiers 19.3.1 Classes of local identifiers 1 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, ...

19.1 1 An entity is identified by an identifier. 2 The scope of • a local identifier is an inclusive scope,

19.3 Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class, ....

3.87 inclusive scope nonblock scoping unit plus every block scoping unit whose host is that scoping unit or that is nested within such a block scoping unit Note 1 to entry: That is, inclusive scope is the scope as if BLOCK constructs were not scoping units.

3.123.1 block scoping unit scoping unit of a BLOCK construct

gklimowicz commented 4 years ago

Just information: Intel 20 and NAG 7 detect this error, but it doesn't appear that gfortran does.