fix(xlaqp2rk): do not modify [in] argument KMAX; introduce KBOUND#1202
Open
nakatamaho wants to merge 1 commit intoReference-LAPACK:masterfrom
Open
fix(xlaqp2rk): do not modify [in] argument KMAX; introduce KBOUND#1202nakatamaho wants to merge 1 commit intoReference-LAPACK:masterfrom
nakatamaho wants to merge 1 commit intoReference-LAPACK:masterfrom
Conversation
In all four variants (SLAQP2RK, DLAQP2RK, CLAQP2RK, ZLAQP2RK),
KMAX was declared as [in] in the documentation but was overwritten
internally via:
KMAX = MIN( KMAX, MINMNFACT )
This is a bug in the reference LAPACK implementation: the Fortran
calling convention silently tolerates this when the caller passes
a temporary expression, but the intent annotation is violated and
C/C++ translations fail to compile (cannot bind rvalue to non-const
reference).
Introduce local variable KBOUND to hold the clamped value:
KBOUND = MIN( KMAX, MINMNFACT )
and replace all subsequent uses of KMAX in the executable section
(loop bound and final assignment K = KBOUND) with KBOUND.
KMAX itself is no longer modified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
SLAQP2RK,DLAQP2RK,CLAQP2RK, andZLAQP2RK, the argumentKMAXis documented as[in], but the implementation overwrites it:This is a contradiction between the documentation and the implementation.
Root cause
Fortran callers are insulated from this side effect because
DGEQP3RK(and its variants) pass a temporary expressionJMAX - J + 1rather than a named variable, so the write toKMAXinsidexLAQP2RKis silently discarded. However:[in]annotation is violated.Fix
Introduce a local variable
KBOUNDto hold the clamped value.KMAXis no longer written to.Files changed
SRC/slaqp2rk.fSRC/dlaqp2rk.fSRC/claqp2rk.fSRC/zlaqp2rk.fNo behavior change
The computed result is identical for all existing callers. This is a correctness fix for the argument intent annotation and a robustness fix for non-Fortran consumers of these routines.