[flang-commits] [flang] 66a2d4b - [flang] Ensure that the integer for Cray pointer is sized correctly (#140822)
via flang-commits
flang-commits at lists.llvm.org
Tue May 27 10:08:38 PDT 2025
Author: Eugene Epshteyn
Date: 2025-05-27T13:08:35-04:00
New Revision: 66a2d4b1e7b54a906990d8cee6174c228604830b
URL: https://github.com/llvm/llvm-project/commit/66a2d4b1e7b54a906990d8cee6174c228604830b
DIFF: https://github.com/llvm/llvm-project/commit/66a2d4b1e7b54a906990d8cee6174c228604830b.diff
LOG: [flang] Ensure that the integer for Cray pointer is sized correctly (#140822)
The integer used for Cray pointers should have the size equivalent to
platform's pointer size.
Added:
Modified:
flang/include/flang/Evaluate/target.h
flang/include/flang/Tools/TargetSetup.h
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index cc6172b492b3c..7b38db2db1956 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 integerKindForPointer() { return integerKindForPointer_; }
+ void set_integerKindForPointer(std::size_t newKind) {
+ integerKindForPointer_ = newKind;
+ }
+
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 integerKindForPointer_{8}; /* For 64 bit pointer */
};
} // namespace Fortran::evaluate
diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h
index de3fb0519cf6b..002e82aa72484 100644
--- a/flang/include/flang/Tools/TargetSetup.h
+++ b/flang/include/flang/Tools/TargetSetup.h
@@ -94,6 +94,10 @@ namespace Fortran::tools {
if (targetTriple.isOSWindows())
targetCharacteristics.set_isOSWindows(true);
+ // Currently the integer kind happens to be the same as the byte size
+ targetCharacteristics.set_integerKindForPointer(
+ 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 3f4a06444c4f3..a8dbf61c8fd68 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6689,8 +6689,8 @@ void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
"'%s' cannot be a Cray pointer as it is already a Cray pointee"_err_en_US);
}
pointer->set(Symbol::Flag::CrayPointer);
- const DeclTypeSpec &pointerType{MakeNumericType(
- TypeCategory::Integer, context().defaultKinds().subscriptIntegerKind())};
+ const DeclTypeSpec &pointerType{MakeNumericType(TypeCategory::Integer,
+ context().targetCharacteristics().integerKindForPointer())};
const auto *type{pointer->GetType()};
if (!type) {
pointer->SetType(pointerType);
More information about the flang-commits
mailing list