[all-commits] [llvm/llvm-project] c664d0: [flang] Avoid signed integer overflow in GetNonNeg...

Eugene Epshteyn via All-commits all-commits at lists.llvm.org
Wed Sep 9 08:21:55 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c664d0dccabe6fc40900f6223284cefe4070a1bf
      https://github.com/llvm/llvm-project/commit/c664d0dccabe6fc40900f6223284cefe4070a1bf
  Author: Eugene Epshteyn <eepshteyn at nvidia.com>
  Date:   2026-09-09 (Wed, 09 Sep 2026)

  Changed paths:
    M flang/lib/Evaluate/shape.cpp

  Log Message:
  -----------
  [flang] Avoid signed integer overflow in GetNonNegativeExtent (#222207)

`GetNonNegativeExtent()` computes a dimension's extent from constant
bounds as `ub - lb + 1` in `ConstantSubscript` (`int64_t`) arithmetic.
For an oversized dimension such as `integer(1) ::
a(0_8:9223372036854775807_8)`, whose extent is 2\*\*63, that computation
overflows — undefined behavior, and the ubsan failure reported in
#221940.

The wrapped result has to be preserved: storage sequences that are too
large are diagnosed later, while offsets are computed, and that code
tells a genuinely empty dimension from one whose extent wrapped around
by cross-checking the original bounds (`IsEmptyDimension()` in
`Semantics/compute-offsets.cpp`). This patch therefore computes the same
two's complement result with `llvm::SubOverflow()` and
`llvm::AddOverflow()`, which are defined for every input. Subtracting
first also covers bounds of mixed sign, where `ub - lb` can overflow
before the increment.

Fixes #221940

Assisted-by: AI



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list