[flang-commits] [flang] [flang] Ensure that the integer for Cray pointer is sized correctly (PR #140822)
via flang-commits
flang-commits at lists.llvm.org
Tue May 20 16:53:50 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Eugene Epshteyn (eugeneepshteyn)
<details>
<summary>Changes</summary>
The integer used for Cray pointers should have the size equivalent to platform's pointer size.
---
Full diff: https://github.com/llvm/llvm-project/pull/140822.diff
3 Files Affected:
- (modified) flang/include/flang/Evaluate/target.h (+6)
- (modified) flang/include/flang/Tools/TargetSetup.h (+3)
- (modified) flang/lib/Semantics/resolve-names.cpp (+1-1)
``````````diff
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index cc6172b492b3c..281e42d5285fb 100644
--- a/flang/include/flang/Evaluate/target.h
+++ b/flang/include/flang/Evaluate/target.h
@@ -131,6 +131,11 @@ class TargetCharacteristics {
IeeeFeatures &ieeeFeatures() { return ieeeFeatures_; }
const IeeeFeatures &ieeeFeatures() const { return ieeeFeatures_; }
+ std::size_t pointerSize() { return pointerSize_; }
+ void set_pointerSize(std::size_t pointerSize) {
+ pointerSize_ = pointerSize;
+ }
+
private:
static constexpr int maxKind{common::maxKind};
std::uint8_t byteSize_[common::TypeCategory_enumSize][maxKind + 1]{};
@@ -156,6 +161,7 @@ class TargetCharacteristics {
IeeeFeature::Io, IeeeFeature::NaN, IeeeFeature::Rounding,
IeeeFeature::Sqrt, IeeeFeature::Standard, IeeeFeature::Subnormal,
IeeeFeature::UnderflowControl};
+ std::size_t pointerSize_{8 /* bytes */};
};
} // namespace Fortran::evaluate
diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h
index de3fb0519cf6b..a30c725e21fb4 100644
--- a/flang/include/flang/Tools/TargetSetup.h
+++ b/flang/include/flang/Tools/TargetSetup.h
@@ -94,6 +94,9 @@ namespace Fortran::tools {
if (targetTriple.isOSWindows())
targetCharacteristics.set_isOSWindows(true);
+ targetCharacteristics.set_pointerSize(
+ targetTriple.getArchPointerBitWidth() / 8);
+
// TODO: use target machine data layout to set-up the target characteristics
// type size and alignment info.
}
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 92a3277191ae0..2f6fe4fea4da2 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6690,7 +6690,7 @@ void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
}
pointer->set(Symbol::Flag::CrayPointer);
const DeclTypeSpec &pointerType{MakeNumericType(
- TypeCategory::Integer, context().defaultKinds().subscriptIntegerKind())};
+ TypeCategory::Integer, context().targetCharacteristics().pointerSize())};
const auto *type{pointer->GetType()};
if (!type) {
pointer->SetType(pointerType);
``````````
</details>
https://github.com/llvm/llvm-project/pull/140822
More information about the flang-commits
mailing list