[flang-commits] [PATCH] D159023: [flang] Handle typeless (BOZ) arguments in AreCompatibleTypes()
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Aug 28 15:09:22 PDT 2023
klausler created this revision.
klausler added a reviewer: vzakhari.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The current code can crash due to the representation's use of a negative
INTEGER kind code to signify a typeless (BOZ) argument's "type" as a
DynamicType. Detect and handle that case, and change some direct
uses of the kind_ data member into kind() accessor references in
places that shouldn't be confronted with BOZ.
https://reviews.llvm.org/D159023
Files:
flang/lib/Evaluate/type.cpp
Index: flang/lib/Evaluate/type.cpp
===================================================================
--- flang/lib/Evaluate/type.cpp
+++ flang/lib/Evaluate/type.cpp
@@ -179,7 +179,7 @@
}
}
} else {
- return targetCharacteristics.GetAlignment(category_, kind_);
+ return targetCharacteristics.GetAlignment(category_, kind());
}
return 1; // needs to be after switch to dodge a bogus gcc warning
}
@@ -193,14 +193,14 @@
case TypeCategory::Complex:
case TypeCategory::Logical:
return Expr<SubscriptInteger>{
- context.targetCharacteristics().GetByteSize(category_, kind_)};
+ context.targetCharacteristics().GetByteSize(category_, kind())};
case TypeCategory::Character:
if (auto len{charLength ? Expr<SubscriptInteger>{Constant<SubscriptInteger>{
*charLength}}
: GetCharLength()}) {
return Fold(context,
Expr<SubscriptInteger>{
- context.targetCharacteristics().GetByteSize(category_, kind_)} *
+ context.targetCharacteristics().GetByteSize(category_, kind())} *
std::move(*len));
}
break;
@@ -540,7 +540,11 @@
return x.kind() == y.kind() &&
(ignoreLengths || !xLen || !yLen || *xLen == *yLen);
} else if (x.category() != TypeCategory::Derived) {
- return x.kind() == y.kind();
+ if (x.IsTypelessIntrinsicArgument()) {
+ return y.IsTypelessIntrinsicArgument();
+ } else {
+ return !y.IsTypelessIntrinsicArgument() && x.kind() == y.kind();
+ }
} else {
const auto *xdt{GetDerivedTypeSpec(x)};
const auto *ydt{GetDerivedTypeSpec(y)};
@@ -651,7 +655,7 @@
case TypeCategory::Integer:
switch (that.category_) {
case TypeCategory::Integer:
- return DynamicType{TypeCategory::Integer, std::max(kind_, that.kind_)};
+ return DynamicType{TypeCategory::Integer, std::max(kind(), that.kind())};
case TypeCategory::Real:
case TypeCategory::Complex:
return that;
@@ -664,9 +668,9 @@
case TypeCategory::Integer:
return *this;
case TypeCategory::Real:
- return DynamicType{TypeCategory::Real, std::max(kind_, that.kind_)};
+ return DynamicType{TypeCategory::Real, std::max(kind(), that.kind())};
case TypeCategory::Complex:
- return DynamicType{TypeCategory::Complex, std::max(kind_, that.kind_)};
+ return DynamicType{TypeCategory::Complex, std::max(kind(), that.kind())};
default:
CRASH_NO_CASE;
}
@@ -677,7 +681,7 @@
return *this;
case TypeCategory::Real:
case TypeCategory::Complex:
- return DynamicType{TypeCategory::Complex, std::max(kind_, that.kind_)};
+ return DynamicType{TypeCategory::Complex, std::max(kind(), that.kind())};
default:
CRASH_NO_CASE;
}
@@ -685,7 +689,7 @@
case TypeCategory::Logical:
switch (that.category_) {
case TypeCategory::Logical:
- return DynamicType{TypeCategory::Logical, std::max(kind_, that.kind_)};
+ return DynamicType{TypeCategory::Logical, std::max(kind(), that.kind())};
default:
CRASH_NO_CASE;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159023.554065.patch
Type: text/x-patch
Size: 3155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230828/27778b08/attachment-0001.bin>
More information about the flang-commits
mailing list