[flang-commits] [clang] [flang] [flang] Warn rather than error on out-of-range constant subscripts (PR #220435)
Ron Green [NVIDIA] via flang-commits
flang-commits at lists.llvm.org
Thu Sep 3 14:58:52 PDT 2026
================
@@ -1,36 +1,39 @@
-! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING %s
-! RUN: not %flang_fc1 -fsyntax-only -Wno-bad-value-in-dead-code %s 2>&1 | FileCheck %s
+! Out-of-range constant subscripts are warnings by default, so use
+! -fno-out-of-bounds-subscripts here to exercise the downgrade of errors to
+! warnings in code that is known at compilation time to be dead.
+! RUN: not %flang_fc1 -fsyntax-only -fno-out-of-bounds-subscripts %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING %s
+! RUN: not %flang_fc1 -fsyntax-only -fno-out-of-bounds-subscripts -Wno-bad-value-in-dead-code %s 2>&1 | FileCheck %s
real a(2)
if (.false.) then
- !CHECK-WARNING::8:12: warning: subscript 3 is greater than upper bound 2 for dimension 1 of array [-Wbad-value-in-dead-code]
+ !CHECK-WARNING::11:12: warning: subscript 3 is greater than upper bound 2 for dimension 1 of array [-Wbad-value-in-dead-code]
print *, a(3)
end if
if (.true.) then
- !CHECK::13:12: error: subscript 0 is less than lower bound 1 for dimension 1 of array
+ !CHECK::16:12: error: subscript 0 is less than lower bound 1 for dimension 1 of array
print *, a(0)
else
- !CHECK-WARNING::16:12: warning: subscript 0 is less than lower bound 1 for dimension 1 of array [-Wbad-value-in-dead-code]
+ !CHECK-WARNING::19:12: warning: subscript 0 is less than lower bound 1 for dimension 1 of array [-Wbad-value-in-dead-code]
print *, a(0)
end if
if (.false.) then
else if (.true.) then
- !CHECK::22:12: error: subscript 0 is less than lower bound 1 for dimension 1 of array
+ !CHECK::25:12: error: subscript 0 is less than lower bound 1 for dimension 1 of array
----------------
ronGreenNV wrote:
Good point — fixed in 0c4bb7b. The absolute line numbers are gone; the diagnostics are distinguished by their text and by the order FileCheck matches them, and the counts still line up exactly (5 dead-code warnings against 5 `CHECK-WARNING` lines, 2 errors against 2 `CHECK` lines).
This also removes the churn that prompted the comment: adding three lines of explanation at the top of the file had shifted every embedded line number by 3.
https://github.com/llvm/llvm-project/pull/220435
More information about the flang-commits
mailing list