[flang-commits] [flang] [flang][runtime] Fix namelist substring checking (PR #78649)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jan 18 16:16:17 PST 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/78649

An || operator in namelist substring bounds checking really needs to be an && operator so that the substring is viewed as correct only when both its bounds are valid.

Fixes llvm-test-suite/Fortran/gfortran/regression/namelist_40.f90.

>From daa9f5ebb1a71dffb0115ed47c8392f3c0a38914 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Thu, 18 Jan 2024 16:13:46 -0800
Subject: [PATCH] [flang][runtime] Fix namelist substring checking

An || operator in namelist substring bounds checking really
needs to be an && operator so that the substring is viewed as
correct only when both its bounds are valid.

Fixes llvm-test-suite/Fortran/gfortran/regression/namelist_40.f90.
---
 flang/runtime/namelist.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 848ebcf300a3d9..f5d7404fdcb86b 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -313,7 +313,7 @@ static bool HandleSubstring(
         desc.raw().elem_len = 0;
         return true;
       }
-      if (*lower >= 1 || *upper <= chars) {
+      if (*lower >= 1 && *upper <= chars) {
         // Offset the base address & adjust the element byte length
         desc.raw().elem_len = (*upper - *lower + 1) * kind;
         desc.set_base_addr(reinterpret_cast<void *>(



More information about the flang-commits mailing list