From 84c6dc96accc6a0818f196b1a09c9696354a4c19 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 26 Apr 2022 13:29:55 -0700 Subject: [PATCH] [flang] Downgrade a fatal error to a warning A non-CHARACTER expression in a CASE statement is allowed to have a distinct kind (not type) from the expression in its SELECT CASE. If a value in a CASE statement is out of range for the SELECT CASE type, emit a warning, but it should not be a fatal error. Differential Revision: https://reviews.llvm.org/D124544 --- flang/lib/Semantics/check-case.cpp | 2 +- flang/test/Semantics/case01.f90 | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flang/lib/Semantics/check-case.cpp b/flang/lib/Semantics/check-case.cpp index 4e37f4e..5bc166e 100644 --- a/flang/lib/Semantics/check-case.cpp +++ b/flang/lib/Semantics/check-case.cpp @@ -94,7 +94,7 @@ private: return value; } else { context_.Say(expr.source, - "CASE value (%s) overflows type (%s) of SELECT CASE expression"_err_en_US, + "CASE value (%s) overflows type (%s) of SELECT CASE expression"_warn_en_US, folded.AsFortran(), caseExprType_.AsFortran()); hasErrors_ = true; return std::nullopt; diff --git a/flang/test/Semantics/case01.f90 b/flang/test/Semantics/case01.f90 index 020f251..7e2d1ef 100644 --- a/flang/test/Semantics/case01.f90 +++ b/flang/test/Semantics/case01.f90 @@ -182,13 +182,13 @@ program test_overflow integer :: j select case(1_1) case (127) - !ERROR: CASE value (128_4) overflows type (INTEGER(1)) of SELECT CASE expression + !WARN: CASE value (128_4) overflows type (INTEGER(1)) of SELECT CASE expression case (128) - !ERROR: CASE value (129_4) overflows type (INTEGER(1)) of SELECT CASE expression - !ERROR: CASE value (130_4) overflows type (INTEGER(1)) of SELECT CASE expression + !WARN: CASE value (129_4) overflows type (INTEGER(1)) of SELECT CASE expression + !WARN: CASE value (130_4) overflows type (INTEGER(1)) of SELECT CASE expression case (129:130) - !ERROR: CASE value (-130_4) overflows type (INTEGER(1)) of SELECT CASE expression - !ERROR: CASE value (-129_4) overflows type (INTEGER(1)) of SELECT CASE expression + !WARN: CASE value (-130_4) overflows type (INTEGER(1)) of SELECT CASE expression + !WARN: CASE value (-129_4) overflows type (INTEGER(1)) of SELECT CASE expression case (-130:-129) case (-128) !ERROR: Must be a scalar value, but is a rank-1 array -- 2.7.4