Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] Static initialization failure when the constant-expr is an array of derived type. #123362

Open
DanielCChen opened this issue Jan 17, 2025 · 1 comment · May be fixed by #123418
Open

[Flang] Static initialization failure when the constant-expr is an array of derived type. #123362

DanielCChen opened this issue Jan 17, 2025 · 1 comment · May be fixed by #123418
Assignees

Comments

@DanielCChen
Copy link
Contributor

Consider the following code:

  PROGRAM  main
  IMPLICIT NONE

  TYPE :: DT
    CHARACTER(38) :: C = "1234567890abcdefghijklmnopqrstuvwxyz  "
    CHARACTER(16) :: C1= "543210  abc ABC "
  END TYPE

  TYPE (DT), PARAMETER :: X(4,4) = DT()
  !TYPE (DT), PARAMETER :: X = DT()      !! Works fine.

  INTEGER(KIND(VERIFY(STRING=X%C, SET=X%C1, KIND=1))) :: &
     &TI1(4,4)=VERIFY(STRING=X%C, SET=X%C1, KIND=1)
end

Flang currently failed to compile the above code as

error: Semantic errors in a4.f
./a4.f:13:16: error: Must be a constant value
       &TI1(4,4)=VERIFY(STRING=X%C, SET=X%C1, KIND=1)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The code seems standard conforming. All ifort, gfortran and XLF compile the code successfully. If X is scalar instead of an array, Flang compiles it fine.

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2025

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code:
  PROGRAM  main
  IMPLICIT NONE

  TYPE :: DT
    CHARACTER(38) :: C = "1234567890abcdefghijklmnopqrstuvwxyz  "
    CHARACTER(16) :: C1= "543210  abc ABC "
  END TYPE

  TYPE (DT), PARAMETER :: X(4,4) = DT()
  !TYPE (DT), PARAMETER :: X = DT()      !! Works fine.

  INTEGER(KIND(VERIFY(STRING=X%C, SET=X%C1, KIND=1))) :: &
     &TI1(4,4)=VERIFY(STRING=X%C, SET=X%C1, KIND=1)
end

Flang currently failed to compile the above code as

error: Semantic errors in a4.f
./a4.f:13:16: error: Must be a constant value
       &TI1(4,4)=VERIFY(STRING=X%C, SET=X%C1, KIND=1)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The code seems standard conforming. All ifort, gfortran and XLF compile the code successfully. If X is scalar instead of an array, Flang compiles it fine.

@klausler klausler self-assigned this Jan 17, 2025
klausler added a commit to klausler/llvm-project that referenced this issue Jan 17, 2025
When a character component reference is applied to a constant
array of derived type, ensure that the length of the resulting
character array is properly defined.

Fixes llvm#123362.
@klausler klausler linked a pull request Jan 17, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants