[flang-commits] [flang] [llvm] [flang] Enumeration Type: (PR 3/5) Intrinsics + I/O + Modules (PR #193235)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 1 00:22:35 PDT 2026
================
@@ -1040,6 +1121,11 @@ void ModFileWriter::PutObjectEntity(
return; // symbol was emitted on STRUCTURE statement
}
}
+ // Enumerator PARAMETERs are emitted as part of the ENUMERATION TYPE
+ // block — suppress standalone emission to avoid duplicates on USE.
+ if (emittedEnumerators_.find(symbol) != emittedEnumerators_.end()) {
----------------
MattPD wrote:
This suppression depends on `PutEnumerationType` having run before the enumerators are visited, i.e., on the enumerators sorting after their type. When an accessibility statement for an enumerator name precedes the `ENUMERATION TYPE`, the enumerator keeps the earlier source position and is emitted as a standalone, forward-referencing PARAMETER before the type block. This module compiles with no error:
```fortran
module m
private :: green
enumeration type :: color
enumerator :: red, green, blue
end enumeration type
end module
```
but the generated `m.mod` places the enumerator before its type:
```
type(color),parameter,private::green=color(2_4)
enumeration type::color
enumerator::red,green,blue
end enumeration type
private::green
```
and `use m` in a separate compilation then crashes with `fatal internal error: CHECK(CanReplaceDetails(details)) failed at .../symbol.cpp(385)`. `private :: green` before the type is valid Fortran, so this looks independent of any duplicate-name question. Could the emission be made order-independent (e.g., populate `emittedEnumerators_` up front, or recognize an enumerator by attribute), so no standalone enumerator is written before its enum block?
https://github.com/llvm/llvm-project/pull/193235
More information about the flang-commits
mailing list