[flang-commits] [flang] [Flang] Do not emit numeric_storage_size into object file (PR #131463)
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Sat Mar 15 10:13:42 PDT 2025
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/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 Evalutate:
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
>From 717d2e8d0b3ede7c513ec7f18a96e82d914e41bf Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Sat, 15 Mar 2025 13:39:54 +0100
Subject: [PATCH] Do not emit numeric_storage_size into object file
---
flang/lib/Lower/Bridge.cpp | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index feab1b7f0a8dc..6e6e88a32517c 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -5967,10 +5967,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
Fortran::lower::pft::getScopeVariableListMap(mod);
for (const auto &var : Fortran::lower::pft::getScopeVariableList(
mod.getScope(), scopeVariableListMap)) {
+
// Only define the variables owned by this module.
const Fortran::semantics::Scope *owningScope = var.getOwningScope();
- if (!owningScope || mod.getScope() == *owningScope)
- Fortran::lower::defineModuleVariable(*this, var);
+ if (owningScope && mod.getScope() != *owningScope)
+ continue;
+
+ // Very special case: 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.
+ if (var.hasSymbol()) {
+ const Fortran::semantics::Symbol &sym = var.getSymbol();
+ const Fortran::semantics::Scope &owner = sym.owner();
+ if (sym.name() == "numeric_storage_size" && owner.IsModule() &&
+ DEREF(owner.symbol()).name() == "iso_fortran_env")
+ continue;
+ }
+
+ Fortran::lower::defineModuleVariable(*this, var);
}
for (auto &eval : mod.evaluationList)
genFIR(eval);
More information about the flang-commits
mailing list