[clang] [clang][Sparc] Pass packed structs and unions in integer registers on SPARC64 (PR #246226)
Matt Turner via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 29 08:18:20 PST 2026
================
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -triple sparcv9-unknown-unknown -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 -triple sparcv9-unknown-unknown -emit-llvm %s -o - \
+// RUN: -fclang-abi-compat=23 | FileCheck %s --check-prefix=COMPAT
+
+// GCC treats base classes like fields when deciding whether a struct with a
+// packed field, or a union, is passed in integer registers on SPARC64.
+
+struct floats {
+ float f, g;
+};
+
+struct packed_base {
+ float f;
+} __attribute__((packed));
+
+// Only the packed base is passed in integer registers.
+struct derived_from_packed : packed_base {
+ float g;
+};
+
+// CHECK-LABEL: define{{.*}} inreg { i32, float } @_Z19derived_from_packed19derived_from_packed(i32 inreg %x.coerce0, float inreg %x.coerce1)
+// COMPAT-LABEL: define{{.*}} inreg { float, float } @_Z19derived_from_packed19derived_from_packed(float inreg %x.coerce0, float inreg %x.coerce1)
+derived_from_packed derived_from_packed(derived_from_packed x) { return x; }
+
+struct base_float {
+ float f;
+};
+
+// A packed class makes its base classes packed.
+struct packed_derived : base_float {
+ float g;
+} __attribute__((packed));
+
+// CHECK-LABEL: define{{.*}} i64 @_Z14packed_derived14packed_derived(i64 %x.coerce)
+// COMPAT-LABEL: define{{.*}} inreg { float, float } @_Z14packed_derived14packed_derived(float inreg %x.coerce0, float inreg %x.coerce1)
+packed_derived packed_derived(packed_derived x) { return x; }
----------------
mattst88 wrote:
`packed_derived` is packed because of `g`. Could you add a packed class with no fields of its own? GCC passes the base's `f` in `%f0`:
```c++
struct packed_base_only : base_float {} __attribute__((packed));
// CHECK-LABEL: define{{.*}} inreg { float, i32 } @_Z16packed_base_only16packed_base_only(float inreg %x.coerce0, i32 inreg %x.coerce1)
// COMPAT-LABEL: define{{.*}} inreg { float, i32 } @_Z16packed_base_only16packed_base_only(float inreg %x.coerce0, i32 inreg %x.coerce1)
packed_base_only packed_base_only(packed_base_only x) { return x; }
```
https://github.com/llvm/llvm-project/pull/246226
More information about the cfe-commits
mailing list