Skip to content

Fix LDSWORK being overwritten during workspace query in xTRSYL3#1206

Merged
langou merged 1 commit intoReference-LAPACK:masterfrom
nakatamaho:fix/trsyl3-ldswork-overwrite
Mar 24, 2026
Merged

Fix LDSWORK being overwritten during workspace query in xTRSYL3#1206
langou merged 1 commit intoReference-LAPACK:masterfrom
nakatamaho:fix/trsyl3-ldswork-overwrite

Conversation

@nakatamaho
Copy link
Copy Markdown
Contributor

Title: Fix LDSWORK overwrite during workspace query in xTRSYL3

## Summary

Remove the erroneous `LDSWORK = 2` assignment in the workspace query
branch of STRSYL3, DTRSYL3, CTRSYL3, and ZTRSYL3.

## Problem

When the caller passes `LDSWORK = -1` to perform a workspace query,
the routines overwrite LDSWORK with 2 before returning. This silently
corrupts the caller's variable, violating the documented intent(in)
contract. A subsequent call with the same variable would use
LDSWORK=2 instead of the caller's allocated leading dimension,
potentially triggering the unblocked fallback path or causing
out-of-bounds access.

## Fix

Delete the `LDSWORK = 2` line from all four routines. The assignment
was unnecessary: the only SWORK accesses in the LQUERY branch are
SWORK(1,1) and SWORK(2,1), both in column 1. In Fortran column-major
layout, the offset is `(i-1) + (j-1)*LDSWORK`; with j=1 the LDSWORK
term vanishes, so the stores are valid regardless of the LDSWORK value.

## Files changed

- SRC/strsyl3.f
- SRC/dtrsyl3.f
- SRC/ctrsyl3.f
- SRC/ztrsyl3.f

## Testing

No new tests required. Existing xTRSYL3 tests continue to pass.
The fix is a pure deletion of a dead store that only manifested as
caller-side corruption.

Remove the erroneous "LDSWORK = 2" assignment inside the LQUERY branch
of STRSYL3, DTRSYL3, CTRSYL3, and ZTRSYL3. The assignment overwrites
the caller's input argument, which is declared as intent(in) in the
documentation. The assignment was unnecessary because SWORK(1,1) and
SWORK(2,1) access column 1 only, making the leading dimension
irrelevant for these stores (offset = (i-1) + (j-1)*LDSWORK, j=1).
nakatamaho added a commit to nakatamaho/mplapack that referenced this pull request Mar 24, 2026
Remove the erroneous "LDSWORK = 2" assignment inside the LQUERY branch
of STRSYL3, DTRSYL3, CTRSYL3, and ZTRSYL3. The assignment overwrites
the caller's input argument, which is declared as intent(in) in the
documentation. The assignment was unnecessary because SWORK(1,1) and
SWORK(2,1) access column 1 only, making the leading dimension
irrelevant for these stores (offset = (i-1) + (j-1)*LDSWORK, j=1).

cf. Reference-LAPACK/lapack#1206
@langou
Copy link
Copy Markdown
Contributor

langou commented Mar 24, 2026

I agree that

         LDSWORK = 2

does not work with the intent "input only" for LDSWOKRK. Thanks!

@langou langou merged commit eb5f719 into Reference-LAPACK:master Mar 24, 2026
12 checks passed
@langou
Copy link
Copy Markdown
Contributor

langou commented Mar 24, 2026

The declaration of SWORK at

$ SWORK( LDSWORK, * )

with the variable LDSWORK set to -1 is interesting. I had not realized this was a thing.

nakatamaho added a commit to nakatamaho/mplapack that referenced this pull request Apr 10, 2026
… xTRSYL3

Add two upstream LAPACK patches for the bundled 3.12.1 sources:
- fix test parameters
  Reference-LAPACK/lapack#1211
- fix LDSWORK being overwritten during workspace query in xTRSYL3
  Reference-LAPACK/lapack#1206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants