llvm / llvm/llvm-project

[Flang] Spurious error for zero-sized array constructor with deferred-length type parameter

Open
#191,868 0 comments 0 reactions 0 assignees View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang incorrectly rejects valid Fortran code when a zero-sized array constructor contains an implied-do loop with a deferred-length character variable.

Expected Behavior: A zero-sized array constructor with deferred-length character type parameter should be valid. The length type parameter should be determined from the character variable used in the constructor, even when the implied-do loop has zero iterations.

Actual Behavior: Flang produces the following error:
```
error: Array constructor implied DO loop has no iterations and indeterminate character length
Print *, [(a,i=1,0)]
```

Reproducer:
```
Program deferred_type_parameter_array_constructor
Character(:), Pointer :: a
Allocate(a, Source="ok!")
! zero-sized array constructor should still have a type parameter
Print *, [(a,i=1,0)]
End Program deferred_type_parameter_array_constructor
```

Contributor guide

Open the contributing guide

Research direction

Run the supplied Fortran reproducer with Flang and inspect the handling of deferred-length character parameters in zero-iteration array-constructor implied-do loops. Trace the diagnostic that reports an indeterminate length; done means the valid program compiles and runs without that error while preserving the variable's character length.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.