Skip to content

Commit 123eb75

Browse files
authored
[Flang] Do not emit numeric_storage_size into object file (#131463)
The value of numeric_storage_size depends on compilation options and therefore its value is not yet known when building the builtins runtime. Instead, the parameter is folding a __numeric_storage_size() expression which is loaded into the user program. For the iso_fortran_env object file, omit the symbol as it is never used. Similar tests that ensure that __numeric_storage_size() is not folded until compiling the actual user program exist in FortranEvalutate: https://github.com/llvm/llvm-project/blob/1e6ba3cd2fe96be00b6ed6ba28b3d9f9271d784d/flang/lib/Evaluate/check-expression.cpp#L487-L492 https://github.com/llvm/llvm-project/blob/1e6ba3cd2fe96be00b6ed6ba28b3d9f9271d784d/flang/lib/Evaluate/fold-integer.cpp#L1457-L1460 Required for using CMake to compile the builtin module files. See RFC at https://discourse.llvm.org/t/rfc-building-flangs-builtin-mod-files/84626
1 parent 52de49e commit 123eb75

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5967,10 +5967,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
59675967
Fortran::lower::pft::getScopeVariableListMap(mod);
59685968
for (const auto &var : Fortran::lower::pft::getScopeVariableList(
59695969
mod.getScope(), scopeVariableListMap)) {
5970+
59705971
// Only define the variables owned by this module.
59715972
const Fortran::semantics::Scope *owningScope = var.getOwningScope();
5972-
if (!owningScope || mod.getScope() == *owningScope)
5973-
Fortran::lower::defineModuleVariable(*this, var);
5973+
if (owningScope && mod.getScope() != *owningScope)
5974+
continue;
5975+
5976+
// Very special case: The value of numeric_storage_size depends on
5977+
// compilation options and therefore its value is not yet known when
5978+
// building the builtins runtime. Instead, the parameter is folding a
5979+
// __numeric_storage_size() expression which is loaded into the user
5980+
// program. For the iso_fortran_env object file, omit the symbol as it
5981+
// is never used.
5982+
if (var.hasSymbol()) {
5983+
const Fortran::semantics::Symbol &sym = var.getSymbol();
5984+
const Fortran::semantics::Scope &owner = sym.owner();
5985+
if (sym.name() == "numeric_storage_size" && owner.IsModule() &&
5986+
DEREF(owner.symbol()).name() == "iso_fortran_env")
5987+
continue;
5988+
}
5989+
5990+
Fortran::lower::defineModuleVariable(*this, var);
59745991
}
59755992
for (auto &eval : mod.evaluationList)
59765993
genFIR(eval);

0 commit comments

Comments
 (0)