Skip to content

Commit 6baf002

Browse files
authored
[flang] Downgrade recently added error to a warning (#117217)
An empty array shouldn't be subscripted, but sometimes they are in zero-trip loops in real applications. So change a recently added error message to a warning (off by default).
1 parent 0fe1f85 commit 6baf002

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

flang/include/flang/Common/Fortran-features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
7272
PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
7373
IndexVarRedefinition, IncompatibleImplicitInterfaces, BadTypeForTarget,
7474
VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
75-
MismatchingDummyProcedure)
75+
MismatchingDummyProcedure, SubscriptedEmptyArray)
7676

7777
using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
7878
using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;

flang/lib/Semantics/expression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ void ExpressionAnalyzer::CheckSubscripts(ArrayRef &ref) {
392392
auto dimUB{ToInt64(ub[dim])};
393393
if (dimUB && dimLB && *dimUB < *dimLB) {
394394
AttachDeclaration(
395-
Say("Empty array dimension %d cannot be subscripted as an element or non-empty array section"_err_en_US,
395+
Warn(common::UsageWarning::SubscriptedEmptyArray,
396+
"Empty array dimension %d should not be subscripted as an element or non-empty array section"_err_en_US,
396397
dim + 1),
397398
arraySymbol);
398399
break;

flang/test/Semantics/expr-errors06.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
22
! Check out-of-range subscripts
33
subroutine subr(da)
44
real a(10), da(2,1), empty(1:0,1)
@@ -43,6 +43,6 @@ subroutine subr(da)
4343
print *, empty(1:0,1) ! ok
4444
print *, empty(:,1) ! ok
4545
print *, empty(i:j,k) ! ok
46-
!ERROR: Empty array dimension 1 cannot be subscripted as an element or non-empty array section
46+
!WARNING: Empty array dimension 1 should not be subscripted as an element or non-empty array section
4747
print *, empty(i,1)
4848
end

0 commit comments

Comments
 (0)