<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57084>57084</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Clang implements lp64d ABI incorrectly for inherited structs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SixWeining
      </td>
    </tr>
</table>

<pre>
    
As [the ABI](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#hardware-floating-point-calling-conventionl) described: A struct containing one floating-point real and one integer (or bitfield), in either order, is passed in a floating-point register and an integer register, provided the floating-point real is no more than ABI_FLEN bits wide and the integer is no more than XLEN bits wide, and at least one floating-point argument register and at least one integer argument register is available. 

Values are returned in the same manner as a first named argument of the same type would be passed.

But for this C++ code:
```
// test.cpp
struct Parent {
  int i;
};

struct Child : Parent {
  float f;
};

struct Child foo(struct Child x) {
  return x;
}
```

```
$ ./build/bin/clang++ --target=riscv64 -mabi=lp64d -emit-llvm -S test.cpp -o -
; ModuleID = 'test.cpp'
source_filename = "test.cpp"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
target triple = "riscv64"

%struct.Child = type { %struct.Parent, float }
%struct.Parent = type { i32 }

; Function Attrs: mustprogress noinline nounwind optnone
define dso_local float @_Z3foo5Child(float %0) #0 {                       ;;;;;;;;;;;; Error: Only the float is passed and returned.
entry:
  %retval = alloca %struct.Child, align 4
  %x = alloca %struct.Child, align 4
  %1 = getelementptr inbounds <{ [4 x i8], float }>, ptr %x, i32 0, i32 1
  store float %0, ptr %1, align 4
  %i = getelementptr inbounds %struct.Parent, ptr %retval, i32 0, i32 0
  store i32 1, ptr %i, align 4
  %2 = getelementptr inbounds <{ [4 x i8], float }>, ptr %retval, i32 0, i32 1
  %3 = load float, ptr %2, align 4
  ret float %3
}

attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,-save-restore" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, !"target-abi", !"lp64d"}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{i32 1, !"SmallDataLimit", i32 8}
!4 = !{!"clang version 16.0.0 (...)"}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytV9tu4zYQ_Rr5haAgUfIlD35I4g2wwPaCBmiLvgSUNLLZUqRAUk7Sr--QlGU59m63QANFFMnhmcOZ4Qxd6eZ9m2S7JLu_tyRZPrgDkPuHz8lyl7DNwbneJsV9wp7w2Qt3GKq01h12jLD1kSqtqLB86oNsaW95JWijaxytpK6w6bh1YCapuk55mC8O3DSv3ABtpeZOqD3ttVCO1lxK36u1OoJyQiuZsDvSgK2NqKBBTuSeWGeG2hEUclwolCdaAbmEIga4JFw1YQ4HYA-G4N60IZVwrQDZIHTCHnGSAG4Rp7VpPF0csqTn1kLjJ_k19F74jQV4rib007hH6I0-igYBvGFvUUMVSpNOG0ARBEHjvzx9-fSjZ2fJK64N8H75Cf_jkt8vxL3WQMgRCWj4W0bhZj90cLWF-YqTsmtRVM-PXEheSUhJDJ74_pXLAXAWiRlwg1HRcJ675R2QjivlIa23pTCoSeFwc9ah27Owe--BvOpBNqSC0Q3pXNvD4EiLbnQHZPSYsAd8MBjQAsUokayy8YndEMbEgXVp3fdxcAyin5E0EkjWD3GYeAMQkRRjP1nvzt_zhY8HgQx9QF5DBKuT9ntBWq0xMC-G3nzYzxCjWXF4Dnlzr7cNUJLUH8tB-Kh_qoTCdy252o_mo9ShM8AlxS6c1VVJaIfnGfuyX5UNodAJR6U8doQ-T6YkVBM66igeyA-6GSR83qFZ8J-tJ4uz9bhtP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