[Flang] Spurious error for DATA statement in BLOCK construct when variable name shadows host scope object
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Flang incorrectly rejects valid Fortran code when a BLOCK construct begins with a DATA statement that initializes a variable whose name exists in the host scope.
Expected Behavior: According to Fortran standards, a variable declared within a BLOCK construct is a construct entity that should shadow any variable with the same name in the host scope. Both the host variable and the block-local variable can be independently initialized with DATA statements.
Actual Behavior: Flang produces the following error:
```
Host-associated object 'n' must not be initialized in a DATA statement
Data n/-20/ ! a block construct entity
```
Reproducer:
```fortran
Program test
Data n/42/
Logical :: no_problem = .True.
Do it=1,12
Block
! Integer n ! adding this helps Flang compile it
Data n/-20/ ! a block construct entity
n = n + 3
If (n .ne. -20+3*it) Then
Print '("fail A",I0)', it
no_problem = .False.
End If
End Block
n = n + 1 ! outer
If (n .ne. 42+it) Then
Print '("fail B",I0)', it
no_problem = .False.
End If
If (.not. no_problem) Exit
End Do
If (no_problem) Print '("ok")'
End Program
```
Contributor guide
Research direction
Start by compiling the supplied Fortran reproducer with Flang and tracing how DATA statements are analyzed inside a BLOCK construct when the name also exists in the host scope. Confirm that the block-local and host variables can be initialized independently, and verify the reproducer compiles and prints the expected result without the spurious host-associated-object error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100