flang-compiler / f18

F18 is a front-end for Fortran intended to replace the existing front-end in the Flang compiler
230 stars 48 forks source link

Construct names check misses inclusive scope rule #1103

Open kiranchandramohan opened 4 years ago

kiranchandramohan commented 4 years ago

For the program given below (or a similar program where block with name lp replaced by do loops) f18 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

kiranchandramohan commented 4 years ago

https://github.com/banach-space is looking into this issue. @sscalpone Can this issue be assigned to him?