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

Roger Ferrer Ibanez via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 00:53:20 PDT 2023


rogfer01 added a comment.

I didn't have libcxx handy but @SixWeining testcase also failed with libstdcxx so I made a slightly smaller standalone testcase based on what libstdcxx does and I manually replaced all the template stuff.

  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;
  
    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 simplify it further by removing the `my_pred_iter` / `my_iter_pred` adapter but then it would not crash anymore. Hope this helps.


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

https://reviews.llvm.org/D142327



More information about the llvm-commits mailing list