[flang-commits] [PATCH] D145747: [flang] Diagnose ridiculously large kind parameters
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Mar 10 09:44:43 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG085c1971ec58: [flang] Diagnose ridiculously large kind parameters (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145747/new/
https://reviews.llvm.org/D145747
Files:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/kinds02.f90
Index: flang/test/Semantics/kinds02.f90
===================================================================
--- flang/test/Semantics/kinds02.f90
+++ flang/test/Semantics/kinds02.f90
@@ -82,6 +82,8 @@
character(len=*), parameter :: cvar10 = 4_"abcd"
!ERROR: CHARACTER(KIND=8) is not a supported type
character(len=*), parameter :: cvar11 = 8_"abcd"
+!ERROR: Unsupported type kind value (5000000000)
+print *, 123_5000000000
end program
subroutine s(a, b)
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -596,23 +596,24 @@
if (!kindParam) {
return defaultKind;
}
- return common::visit(
+ std::int64_t kind{common::visit(
common::visitors{
- [](std::uint64_t k) { return static_cast<int>(k); },
+ [](std::uint64_t k) { return static_cast<std::int64_t>(k); },
[&](const parser::Scalar<
parser::Integer<parser::Constant<parser::Name>>> &n) {
if (MaybeExpr ie{Analyze(n)}) {
- if (std::optional<std::int64_t> i64{ToInt64(*ie)}) {
- int iv = *i64;
- if (iv == *i64) {
- return iv;
- }
- }
+ return ToInt64(*ie).value_or(defaultKind);
}
- return defaultKind;
+ return static_cast<std::int64_t>(defaultKind);
},
},
- kindParam->u);
+ kindParam->u)};
+ if (kind != static_cast<int>(kind)) {
+ Say("Unsupported type kind value (%jd)"_err_en_US,
+ static_cast<std::intmax_t>(kind));
+ kind = defaultKind;
+ }
+ return static_cast<int>(kind);
}
// Common handling of parser::IntLiteralConstant and SignedIntLiteralConstant
@@ -657,7 +658,7 @@
}
ExpressionAnalyzer &analyzer;
parser::CharBlock digits;
- int kind;
+ std::int64_t kind;
bool isDefaultKind;
bool isNegated;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145747.504189.patch
Type: text/x-patch
Size: 1990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230310/e280b646/attachment-0001.bin>
More information about the flang-commits
mailing list