[clang] [clang][Sparc] Pass packed structs and unions in integer registers on SPARC64 (PR #246226)

Brad Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 29 15:18:13 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; }
----------------
brad0 wrote:

Added, thanks.

https://github.com/llvm/llvm-project/pull/246226


More information about the cfe-commits mailing list