[flang-commits] [flang] [Flang] Do not emit numeric_storage_size into object file (PR #131463)
via flang-commits
flang-commits at lists.llvm.org
Sat Mar 15 13:33:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Michael Kruse (Meinersbur)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/131463.diff
1 Files Affected:
- (modified) flang/lib/Lower/Bridge.cpp (+19-2)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/131463
More information about the flang-commits
mailing list