Skip to content

Commit 72079d9

Browse files
committed
[flang] Handle typeless (BOZ) arguments in AreCompatibleTypes()
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. Differential Revision: https://reviews.llvm.org/D159023
1 parent 18c7bf0 commit 72079d9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

flang/lib/Evaluate/type.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ std::size_t DynamicType::GetAlignment(
179179
}
180180
}
181181
} else {
182-
return targetCharacteristics.GetAlignment(category_, kind_);
182+
return targetCharacteristics.GetAlignment(category_, kind());
183183
}
184184
return 1; // needs to be after switch to dodge a bogus gcc warning
185185
}
@@ -193,14 +193,14 @@ std::optional<Expr<SubscriptInteger>> DynamicType::MeasureSizeInBytes(
193193
case TypeCategory::Complex:
194194
case TypeCategory::Logical:
195195
return Expr<SubscriptInteger>{
196-
context.targetCharacteristics().GetByteSize(category_, kind_)};
196+
context.targetCharacteristics().GetByteSize(category_, kind())};
197197
case TypeCategory::Character:
198198
if (auto len{charLength ? Expr<SubscriptInteger>{Constant<SubscriptInteger>{
199199
*charLength}}
200200
: GetCharLength()}) {
201201
return Fold(context,
202202
Expr<SubscriptInteger>{
203-
context.targetCharacteristics().GetByteSize(category_, kind_)} *
203+
context.targetCharacteristics().GetByteSize(category_, kind())} *
204204
std::move(*len));
205205
}
206206
break;
@@ -540,7 +540,11 @@ static bool AreCompatibleTypes(const DynamicType &x, const DynamicType &y,
540540
return x.kind() == y.kind() &&
541541
(ignoreLengths || !xLen || !yLen || *xLen == *yLen);
542542
} else if (x.category() != TypeCategory::Derived) {
543-
return x.kind() == y.kind();
543+
if (x.IsTypelessIntrinsicArgument()) {
544+
return y.IsTypelessIntrinsicArgument();
545+
} else {
546+
return !y.IsTypelessIntrinsicArgument() && x.kind() == y.kind();
547+
}
544548
} else {
545549
const auto *xdt{GetDerivedTypeSpec(x)};
546550
const auto *ydt{GetDerivedTypeSpec(y)};
@@ -651,7 +655,7 @@ DynamicType DynamicType::ResultTypeForMultiply(const DynamicType &that) const {
651655
case TypeCategory::Integer:
652656
switch (that.category_) {
653657
case TypeCategory::Integer:
654-
return DynamicType{TypeCategory::Integer, std::max(kind_, that.kind_)};
658+
return DynamicType{TypeCategory::Integer, std::max(kind(), that.kind())};
655659
case TypeCategory::Real:
656660
case TypeCategory::Complex:
657661
return that;
@@ -664,9 +668,9 @@ DynamicType DynamicType::ResultTypeForMultiply(const DynamicType &that) const {
664668
case TypeCategory::Integer:
665669
return *this;
666670
case TypeCategory::Real:
667-
return DynamicType{TypeCategory::Real, std::max(kind_, that.kind_)};
671+
return DynamicType{TypeCategory::Real, std::max(kind(), that.kind())};
668672
case TypeCategory::Complex:
669-
return DynamicType{TypeCategory::Complex, std::max(kind_, that.kind_)};
673+
return DynamicType{TypeCategory::Complex, std::max(kind(), that.kind())};
670674
default:
671675
CRASH_NO_CASE;
672676
}
@@ -677,15 +681,15 @@ DynamicType DynamicType::ResultTypeForMultiply(const DynamicType &that) const {
677681
return *this;
678682
case TypeCategory::Real:
679683
case TypeCategory::Complex:
680-
return DynamicType{TypeCategory::Complex, std::max(kind_, that.kind_)};
684+
return DynamicType{TypeCategory::Complex, std::max(kind(), that.kind())};
681685
default:
682686
CRASH_NO_CASE;
683687
}
684688
break;
685689
case TypeCategory::Logical:
686690
switch (that.category_) {
687691
case TypeCategory::Logical:
688-
return DynamicType{TypeCategory::Logical, std::max(kind_, that.kind_)};
692+
return DynamicType{TypeCategory::Logical, std::max(kind(), that.kind())};
689693
default:
690694
CRASH_NO_CASE;
691695
}

0 commit comments

Comments
 (0)