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

Lu Weining via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 20:50:51 PDT 2023


SixWeining added inline comments.


================
Comment at: clang/lib/CodeGen/Targets/RISCV.cpp:178
       return false;
-    if (isEmptyRecord(getContext(), Ty, true))
+    if (isEmptyRecord(getContext(), Ty, true, true))
       return true;
----------------
asb wrote:
> rogfer01 wrote:
> > I've observed (based on manually added tracing) that we may return true here with `Field1Ty == nullptr` and `Field2Ty == nullptr`.
> > 
> > Then `RISCVABIInfo::coerceAndExpandFPCCEligibleStruct` receives these two types and appends `Field1Ty` it into `UnpaddedCoerceElts` and then if `Field2Ty == nullptr` it calls `ABIArgInfo::getCoerceAndExpand` (around line 280 of `clang/lib/CodeGen/Targets/RISCV.cpp`) which then tries to do a `dyn_cast` on a null value and then an assertion fires (around line 256 of `clang/include/clang/CodeGen/CGFunctionInfo.h`)
> > 
> > I can reproduce this with the llvm-testsuite. Apologies that I have not managed to create a small reproducer yet.
> Thank you, I've reverted until this can be investigated and fixed.
LoongArch has the same issue and I write a reproducer:
```
$ cat test.cpp
#include <algorithm>
#include <vector>

static bool check(int i) {
  return i == 2;
}

int main()
{
  std::vector<int> v{1, 2, 3, 2, 2};
  //return std::count_if(v.begin(), v.end(), check); // ok
  return std::count_if(v.begin(), v.end(), [](int i) { return i == 2; }); // error
}
```

Let's investigate how to fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142327



More information about the cfe-commits mailing list