[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

Roger Ferrer Ibanez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 27 00:58:25 PDT 2023


rogfer01 added a comment.

I didn't have libcxx handy but @SixWeining testcase also fails with libstdcxx so I expanded what C++ does and removed the templates.

With the new patch this does not fail anymore.

  typedef decltype((int *)2 - (int *)1) my_ptrdiff_t;
  
  struct my_lambda {
    bool operator()(int i) { return i == 2; }
  };
  
  struct my_iter_pred {
    my_lambda _M_pred;
  
    explicit my_iter_pred(my_lambda __pred)
        : _M_pred(/* move */ static_cast<my_lambda &&>(__pred)) {}
  
    bool operator()(int *__it) { return bool(_M_pred(*__it)); }
  };
  
  my_ptrdiff_t __my_count_if(int *__first, int *__last, my_iter_pred __pred) {
    my_ptrdiff_t __n = 0;
    for (; __first != __last; ++__first)
      if (__pred(__first))
        ++__n;
    return __n;
  }
  
  inline my_iter_pred my_pred_iter(my_lambda __my_lambda) {
    return my_iter_pred(/* move */ static_cast<my_lambda &&>(__my_lambda));
  }
  
  inline my_ptrdiff_t my_count_if(int *__first, int *__last,
                                  my_lambda __my_lambda) {
    return __my_count_if(__first, __last, my_pred_iter(__my_lambda));
  }
  
  int main() {
    int v[] = {1, 2, 3, 2, 2};
    return my_count_if(v, v + sizeof(v) / sizeof(*v), my_lambda());
  }

I tried to remove the `my_pred_iter` / `my_iter_pred` wrapper but then the original patch would not fail anymore.

Hope this helps.


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

https://reviews.llvm.org/D142327



More information about the cfe-commits mailing list