Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Fix namelist substring checking #78649

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

klausler
Copy link
Contributor

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.

@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 19, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 19, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/78649.diff

1 Files Affected:

  • (modified) flang/runtime/namelist.cpp (+1-1)
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 *>(

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
and .../namelist_47.f90.
@klausler klausler merged commit 15e4a3c into llvm:main Jan 25, 2024
4 checks passed
@klausler klausler deleted the namelist40 branch January 25, 2024 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants