[PATCH] D127434: [clang][dataflow] In `optional` model, match call return via hasType

Stanislav Gatev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 10 01:24:29 PDT 2022


sgatev added a comment.

I see that the declaration of `operator*` in `std::unique_ptr` is `typename add_lvalue_reference<T>::type operator*() const;`. I managed to reproduce the crash with the following snippet:

  #include <optional>
  
  namespace detail {
   
  template <class T>
  struct type_identity { using type = T; };
  
  template <class T>
  auto try_add_lvalue_reference(int) -> type_identity<T&>;
  
  template <class T>
  auto try_add_lvalue_reference(...) -> type_identity<T>;
  
  template <class T>
  auto try_add_rvalue_reference(int) -> type_identity<T&&>;
  
  template <class T>
  auto try_add_rvalue_reference(...) -> type_identity<T>;
  
  }  // namespace detail
  
  template <class T>
  struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference<T>(0)) {};
  
  template <class T>
  struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference<T>(0)) {};
  
  template <typename T>
  struct smart_ptr {
    typename add_lvalue_reference<T>::type operator*() &;
  };
  
  void foo() {
    smart_ptr<std::optional<float>> x;
    *x = std::nullopt;
  }

I suggest adding the definition of `add_lvalue_reference` to StdTypeTraitsHeader <https://github.com/llvm/llvm-project/blob/f93dee10336a2361da528db0ff0f7188acba9627/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp#L48> and adding a test with the rest of the code above.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127434/new/

https://reviews.llvm.org/D127434



More information about the cfe-commits mailing list