[all-commits] [llvm/llvm-project] ec1394: [flang] prevent undefined behavior in character MA...

jeanPerier via All-commits all-commits at lists.llvm.org
Tue Mar 29 00:34:51 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ec13942e71daad88267d73ff57b854b816c2a722
      https://github.com/llvm/llvm-project/commit/ec13942e71daad88267d73ff57b854b816c2a722
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2022-03-29 (Tue, 29 Mar 2022)

  Changed paths:
    M flang/lib/Evaluate/fold-integer.cpp
    M flang/test/Evaluate/fold-findloc.f90

  Log Message:
  -----------
  [flang] prevent undefined behavior in character MAXLOC folding

When folding MAXLOC/MINLOC, the current element being compared was moved twice
in row in case it became the new extremum. With numeric and logical types, it
made no difference (std::move is a no-op for them), but for characters
where the string storage is actually moved, it caused the new extremum to
be set to the empty string, leading to wrong results.

Note: I could have left the first std::move relating to logical Findloc, but it
brings nothing and makes the code less auditable, so I also removed it.

Differential Revision: https://reviews.llvm.org/D122590




More information about the All-commits mailing list