-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
base: main
Are you sure you want to change the base?
Conversation
The integer used for Cray pointers should have the size equivalent to platform's pointer size. modified: flang/include/flang/Evaluate/target.h modified: flang/include/flang/Tools/TargetSetup.h modified: flang/lib/Semantics/resolve-names.cpp
@llvm/pr-subscribers-flang-semantics Author: Eugene Epshteyn (eugeneepshteyn) ChangesThe 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:
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);
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names in this code assumes that integer kinds equal their byte sizes. Steve has been wanting me to make the kind/size relationship configurable, or to at least not always have that assumption by having mapping functions.
integerKindForPointer
or something along those lines would avoid that assumption. We don't really need a byte size here, since it's just a selection of an integer kind.
Looks good. Thanks. |
The integer used for Cray pointers should have the size equivalent to platform's pointer size.