[all-commits] [llvm/llvm-project] 1264ff: [clang][RISC-V] fixed fp calling convention for fp...

Kamran Yousafzai via All-commits all-commits at lists.llvm.org
Fri Mar 27 16:55:33 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1264ffc4cc17ba8aac19624d478874c2f6bd10d8
      https://github.com/llvm/llvm-project/commit/1264ffc4cc17ba8aac19624d478874c2f6bd10d8
  Author: Kamran Yousafzai <yousafzai.mkamran at gmail.com>
  Date:   2026-03-27 (Fri, 27 Mar 2026)

  Changed paths:
    M clang/lib/CodeGen/Targets/RISCV.cpp
    A clang/test/CodeGen/RISCV/riscv-fpcc-struct.c
    M clang/test/CodeGen/RISCV/riscv64-abi.c

  Log Message:
  -----------
  [clang][RISC-V] fixed fp calling convention for fpcc eligible structs for risc-v (#110690)

The code generated for calls with FPCC eligible structs as arguments
doesn't consider the bitfield, which results in a store crossing the
boundary of the memory allocated using alloca, e.g.
For the code:
```
struct __attribute__((packed, aligned(1))) S {
   const float  f0;
   unsigned f1 : 1;
};
unsigned  func(struct S  arg)
{
    return arg.f1;
} 
```
The generated IR is:
```
 define dso_local signext i32 @func(
 float [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR0:[0-9]+]] {
  [[ENTRY:.*:]]
    [[ARG:%.*]] = alloca [[STRUCT_S:%.*]], align 1
    [[TMP2:%.*]] = getelementptr inbounds nuw { float, i32 }, ptr [[ARG]], i32 0, i32 0
    store float [[TMP0]], ptr [[TMP2]], align 1
    [[TMP3:%.*]] = getelementptr inbounds nuw { float, i32 }, ptr [[ARG]], i32 0, i32 1
    store i32 [[TMP1]], ptr [[TMP3]], align 1
    [[F1:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[ARG]], i32 0, i32 1
    [[BF_LOAD:%.*]] = load i8, ptr [[F1]], align 1
    [[BF_CLEAR:%.*]] = and i8 [[BF_LOAD]], 1
    [[BF_CAST:%.*]] = zext i8 [[BF_CLEAR]] to i32
    ret i32 [[BF_CAST]]
```
Where, `store i32 [[TMP1]], ptr [[TMP3]], align 1` can be seen crossing
the boundary of the allocated memory. If, the IR is seen after
optimizations (EarlyCSEPass), the IR left is:
```
 define dso_local noundef signext i32 @func(
 float [[TMP0:%.*]], i32 [[TMP1:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
  [[ENTRY:.*:]]
    ret i32 0
```
The patch trims the second member of the struct after taking into
consideration the bitwidth to decide the appropriate integer type and
the test shows the results of this patch.

Note that the bug is seen only when `f` extension is enabled for FPCC
eligibility.

Co-authored-by: muhammad.kamran4 <muhammad.kamran at esperantotech.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list