Skip to content

[flang] Ensure that the integer for Cray pointer is sized correctly #140822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flang/include/flang/Evaluate/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]{};
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions flang/include/flang/Tools/TargetSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down