[flang-commits] [flang] 6baf002 - [flang] Downgrade recently added error to a warning (#117217)

via flang-commits flang-commits at lists.llvm.org
Mon Dec 2 12:25:01 PST 2024


Author: Peter Klausler
Date: 2024-12-02T12:24:58-08:00
New Revision: 6baf0023ce7f880a15aa89eaea2dcbea59abfa16

URL: https://github.com/llvm/llvm-project/commit/6baf0023ce7f880a15aa89eaea2dcbea59abfa16
DIFF: https://github.com/llvm/llvm-project/commit/6baf0023ce7f880a15aa89eaea2dcbea59abfa16.diff

LOG: [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).

Added: 
    

Modified: 
    flang/include/flang/Common/Fortran-features.h
    flang/lib/Semantics/expression.cpp
    flang/test/Semantics/expr-errors06.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index c6ab846cce2fc0..5da08abc2c5a83 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -72,7 +72,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
     PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
     IndexVarRedefinition, IncompatibleImplicitInterfaces, BadTypeForTarget,
     VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
-    MismatchingDummyProcedure)
+    MismatchingDummyProcedure, SubscriptedEmptyArray)
 
 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
 using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;

diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index ead99821126787..b9be586f4d7721 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -392,7 +392,8 @@ void ExpressionAnalyzer::CheckSubscripts(ArrayRef &ref) {
     auto dimUB{ToInt64(ub[dim])};
     if (dimUB && dimLB && *dimUB < *dimLB) {
       AttachDeclaration(
-          Say("Empty array dimension %d cannot be subscripted as an element or non-empty array section"_err_en_US,
+          Warn(common::UsageWarning::SubscriptedEmptyArray,
+              "Empty array dimension %d should not be subscripted as an element or non-empty array section"_err_en_US,
               dim + 1),
           arraySymbol);
       break;

diff  --git a/flang/test/Semantics/expr-errors06.f90 b/flang/test/Semantics/expr-errors06.f90
index bdcb92cbe5e4df..07cda25e5cb0c4 100644
--- a/flang/test/Semantics/expr-errors06.f90
+++ b/flang/test/Semantics/expr-errors06.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
 ! Check out-of-range subscripts
 subroutine subr(da)
   real a(10), da(2,1), empty(1:0,1)
@@ -43,6 +43,6 @@ subroutine subr(da)
   print *, empty(1:0,1) ! ok
   print *, empty(:,1) ! ok
   print *, empty(i:j,k) ! ok
-  !ERROR: Empty array dimension 1 cannot be subscripted as an element or non-empty array section
+  !WARNING: Empty array dimension 1 should not be subscripted as an element or non-empty array section
   print *, empty(i,1)
 end


        


More information about the flang-commits mailing list