[all-commits] [llvm/llvm-project] 134c91: [libc++] Fix UB in <expected> related to "has valu...

Jan Kokemüller via All-commits all-commits at lists.llvm.org
Mon Oct 30 11:56:16 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 134c91595568ea1335b22e559f20c1a488ea270e
      https://github.com/llvm/llvm-project/commit/134c91595568ea1335b22e559f20c1a488ea270e
  Author: Jan Kokemüller <jan.kokemueller at gmail.com>
  Date:   2023-10-30 (Mon, 30 Oct 2023)

  Changed paths:
    M libcxx/include/__expected/expected.h
    M libcxx/test/std/utilities/expected/expected.expected/assign/emplace.intializer_list.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/assign/emplace.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.convert.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.convert.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.default.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace_init_list.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.u.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect_init_list.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpected.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpected.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/observers/has_value.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/swap/free.swap.pass.cpp
    M libcxx/test/std/utilities/expected/expected.expected/swap/member.swap.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.convert.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.convert.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect_init_list.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpected.copy.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpected.move.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/observers/has_value.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/swap/free.swap.pass.cpp
    M libcxx/test/std/utilities/expected/expected.void/swap/member.swap.pass.cpp
    M libcxx/test/std/utilities/expected/types.h

  Log Message:
  -----------
  [libc++] Fix UB in <expected> related to "has value" flag (#68552) (#68733)

The calls to std::construct_at might overwrite the previously set
__has_value_ flag in the case where the flag is overlapping with
the actual value or error being stored (since we use [[no_unique_address]]).
To fix this issue, this patch ensures that we initialize the
__has_value_ flag after we call std::construct_at.

Fixes #68552




More information about the All-commits mailing list