llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] Incorrect diagnose for DATA statement

Open DanielCChen opened this issue 2 years ago • 4 comments

Consider the following code:

  PROGRAM Misc7
  INTEGER A(3), B, C(3)
  DATA A(1:2) /2*1/ A(2:3) /2*2/
  DATA C /3*1/ C /3*2/
  DATA B /1/ B /2/
  PRINT*, A
  PRINT*, C
  PRINT*, B
  IF (ANY(A(1:1) .NE. 1 )) ERROR STOP 11
  IF (ANY(A(2:3) .NE. 2 )) ERROR STOP 12
  IF (ANY(C(1:3) .NE. 2 )) ERROR STOP 13
  IF (B          .NE. 2 )  ERROR STOP 14

  END

Flang currently issues error messages

54:11: error: DATA statement initializations affect 'a(2_8)' more than once
    INTEGER A(3), B, C(3)
            ^
 54:17: error: DATA statement initializations affect 'b' more than once
    INTEGER A(3), B, C(3)
                  ^
 54:20: error: DATA statement initializations affect 'c(1_8)' more than once
    INTEGER A(3), B, C(3)
                     ^

It doesn't seem correct to me.

DanielCChen avatar Feb 17 '24 00:02 DanielCChen

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` PROGRAM Misc7 INTEGER A(3), B, C(3) DATA A(1:2) /2*1/ A(2:3) /2*2/ DATA C /3*1/ C /3*2/ DATA B /1/ B /2/ PRINT*, A PRINT*, C PRINT*, B IF (ANY(A(1:1) .NE. 1 )) ERROR STOP 11 IF (ANY(A(2:3) .NE. 2 )) ERROR STOP 12 IF (ANY(C(1:3) .NE. 2 )) ERROR STOP 13 IF (B .NE. 2 ) ERROR STOP 14

END


Flang currently issues error messages

54:11: error: DATA statement initializations affect 'a(2_8)' more than once INTEGER A(3), B, C(3) ^ 54:17: error: DATA statement initializations affect 'b' more than once INTEGER A(3), B, C(3) ^ 54:20: error: DATA statement initializations affect 'c(1_8)' more than once INTEGER A(3), B, C(3) ^


It doesn't seem correct to me.
</details>

llvmbot avatar Feb 17 '24 00:02 llvmbot

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` PROGRAM Misc7 INTEGER A(3), B, C(3) DATA A(1:2) /2*1/ A(2:3) /2*2/ DATA C /3*1/ C /3*2/ DATA B /1/ B /2/ PRINT*, A PRINT*, C PRINT*, B IF (ANY(A(1:1) .NE. 1 )) ERROR STOP 11 IF (ANY(A(2:3) .NE. 2 )) ERROR STOP 12 IF (ANY(C(1:3) .NE. 2 )) ERROR STOP 13 IF (B .NE. 2 ) ERROR STOP 14

END


Flang currently issues error messages

54:11: error: DATA statement initializations affect 'a(2_8)' more than once INTEGER A(3), B, C(3) ^ 54:17: error: DATA statement initializations affect 'b' more than once INTEGER A(3), B, C(3) ^ 54:20: error: DATA statement initializations affect 'c(1_8)' more than once INTEGER A(3), B, C(3) ^


It doesn't seem correct to me.
</details>

llvmbot avatar Feb 17 '24 00:02 llvmbot

Normally, "It doesn't seem correct to me" is followed by a comma and a clause starting with "because ...". flang's behavior is correct.

Fortran 2023, 8.4 Initialization ... A variable, or part of a variable, shall not be explicitly initialized more than once in a program. ...

kargl avatar Feb 19 '24 01:02 kargl

You are right. The standard indeed doesn't allow multiple initialization on the same variable. I missed it. Thanks for pointing it out.

DanielCChen avatar Feb 19 '24 05:02 DanielCChen