[PATCH] D79637: [flang] Make implicit conversion explicit in assignment
Tim Keith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 9 09:33:17 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb05c8c5756e4: [flang] Make implicit conversion explicit in assignment (authored by tskeith).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79637/new/
https://reviews.llvm.org/D79637
Files:
flang/lib/Semantics/expression.cpp
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -184,6 +184,8 @@
std::optional<ActualArgument> AnalyzeExpr(const parser::Expr &);
bool AreConformable() const;
const Symbol *FindBoundOp(parser::CharBlock, int passIndex);
+ void AddAssignmentConversion(
+ const DynamicType &lhsType, const DynamicType &rhsType);
bool OkLogicalIntegerAssignment(TypeCategory lhs, TypeCategory rhs);
std::optional<DynamicType> GetType(std::size_t) const;
int GetRank(std::size_t) const;
@@ -2809,6 +2811,9 @@
Tristate isDefined{
semantics::IsDefinedAssignment(lhsType, lhsRank, rhsType, rhsRank)};
if (isDefined == Tristate::No) {
+ if (lhsType && rhsType) {
+ AddAssignmentConversion(*lhsType, *rhsType);
+ }
return std::nullopt; // user-defined assignment not allowed for these args
}
auto restorer{context_.GetContextualMessages().SetLocation(source_)};
@@ -2939,6 +2944,19 @@
return result;
}
+// If there is an implicit conversion between intrinsic types, make it explicit
+void ArgumentAnalyzer::AddAssignmentConversion(
+ const DynamicType &lhsType, const DynamicType &rhsType) {
+ if (lhsType.category() == rhsType.category() &&
+ lhsType.kind() == rhsType.kind()) {
+ // no conversion necessary
+ } else if (auto rhsExpr{evaluate::ConvertToType(lhsType, MoveExpr(1))}) {
+ actuals_[1] = ActualArgument{*rhsExpr};
+ } else {
+ actuals_[1] = std::nullopt;
+ }
+}
+
std::optional<DynamicType> ArgumentAnalyzer::GetType(std::size_t i) const {
return i < actuals_.size() ? actuals_[i].value().GetType() : std::nullopt;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79637.263021.patch
Type: text/x-patch
Size: 1739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200509/4722d146/attachment.bin>
More information about the llvm-commits
mailing list