Skip to content

dverb2.c: Investigate shift operator precedence ambiguity in mirror room navigation #41

@justwheel

Description

@justwheel

Summary

Clang flags two operator precedence ambiguities in dverb2.c where - is evaluated before <<, potentially diverging from the original FORTRAN intent.

Background

The CI pipeline introduced in PR #38 revealed two -Wshift-op-parentheses warnings from Clang in dverb2.c, both in the mirror/maze room navigation logic.
Line 493: curxt_1.xroom1 - rindex_1.mra << 1 is evaluated as (curxt_1.xroom1 - rindex_1.mra) << 1 because - has higher precedence than <<.
Line 557: findex_1.mloc - rindex_1.mra << 1 follows the same pattern.
If the original FORTRAN intended a multiply-by-two of the subtraction result, the current C code is correct.
If it intended to shift mra first and then subtract, this is a latent navigation bug in the mirror rooms.

Details

  1. Locate the original FORTRAN source for the CXAPPL function (the cxappl_ static function in dverb2.c) to determine the intended arithmetic.
  2. In FORTRAN, ISHFT is the shift operation — determine whether the original used ISHFT(X - Y, 1) or X - ISHFT(Y, 1).
  3. If the C precedence matches the FORTRAN semantics, add explicit parentheses to document the intent and silence the warning.
  4. If the behavior diverges, add parentheses to correct the grouping.

This can be fixed as part of v1.1.0, but will most likely be addressed in a future release to help get recent changes submitted downstream in the Fedora package.

Outcome

The mirror room navigation arithmetic is verified against the original FORTRAN source and parenthesized to remove the ambiguity and silence the Clang -Wshift-op-parentheses warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or produces incorrect behaviorcompiler warningDiscovered via compiler diagnosticsf2c heritageRelated to the FORTRAN-to-C translation lineageneeds investigationRequires deeper analysis before a fix can be proposed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions