Skip to content

Commit 66a2d4b

Browse files
[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.
1 parent 9392652 commit 66a2d4b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

flang/include/flang/Evaluate/target.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class TargetCharacteristics {
131131
IeeeFeatures &ieeeFeatures() { return ieeeFeatures_; }
132132
const IeeeFeatures &ieeeFeatures() const { return ieeeFeatures_; }
133133

134+
std::size_t integerKindForPointer() { return integerKindForPointer_; }
135+
void set_integerKindForPointer(std::size_t newKind) {
136+
integerKindForPointer_ = newKind;
137+
}
138+
134139
private:
135140
static constexpr int maxKind{common::maxKind};
136141
std::uint8_t byteSize_[common::TypeCategory_enumSize][maxKind + 1]{};
@@ -156,6 +161,7 @@ class TargetCharacteristics {
156161
IeeeFeature::Io, IeeeFeature::NaN, IeeeFeature::Rounding,
157162
IeeeFeature::Sqrt, IeeeFeature::Standard, IeeeFeature::Subnormal,
158163
IeeeFeature::UnderflowControl};
164+
std::size_t integerKindForPointer_{8}; /* For 64 bit pointer */
159165
};
160166

161167
} // namespace Fortran::evaluate

flang/include/flang/Tools/TargetSetup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ namespace Fortran::tools {
9494
if (targetTriple.isOSWindows())
9595
targetCharacteristics.set_isOSWindows(true);
9696

97+
// Currently the integer kind happens to be the same as the byte size
98+
targetCharacteristics.set_integerKindForPointer(
99+
targetTriple.getArchPointerBitWidth() / 8);
100+
97101
// TODO: use target machine data layout to set-up the target characteristics
98102
// type size and alignment info.
99103
}

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6689,8 +6689,8 @@ void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
66896689
"'%s' cannot be a Cray pointer as it is already a Cray pointee"_err_en_US);
66906690
}
66916691
pointer->set(Symbol::Flag::CrayPointer);
6692-
const DeclTypeSpec &pointerType{MakeNumericType(
6693-
TypeCategory::Integer, context().defaultKinds().subscriptIntegerKind())};
6692+
const DeclTypeSpec &pointerType{MakeNumericType(TypeCategory::Integer,
6693+
context().targetCharacteristics().integerKindForPointer())};
66946694
const auto *type{pointer->GetType()};
66956695
if (!type) {
66966696
pointer->SetType(pointerType);

0 commit comments

Comments
 (0)