Skip to content

Support packed aggregates passed by value across the kernel ABI #940

Closed

Description

@uurl

Problem

Packed aggregates passed or returned by value are currently rejected because their physical rustc layout cannot be represented faithfully by an ordinary LLVM struct.

For example:

#[repr(C, packed)]
struct Packed1 {
    a: u8,
    b: u32,
}

#[repr(C, packed(2))]
struct Packed2 {
    a: u8,
    b: u32,
}

have the following Rust layouts:

Packed1: size = 5, align = 1, b @ offset 1
Packed2: size = 6, align = 2, b @ offset 2

These layouts cannot be represented faithfully by ordinary LLVM structs.

The expected LLVM representations are:

<{ i8, i32 }>
<{ i8, [1 x i8], i32 }>

respectively.

There is an additional ABI complication for repr(C, packed(2)): an LLVM packed struct has natural alignment 1, while the Rust ABI alignment of the aggregate is 2. That alignment must therefore be preserved separately when the aggregate crosses the kernel parameter ABI.

Scope

Add support for packed aggregates passed by value, including:

  • construction of packed aggregate SSA values;
  • whole-value loads and stores;
  • packed aggregate array stride;
  • kernel parameters passed by value;
  • device-function aggregate arguments and returns;
  • explicit padding required by repr(packed(N));
  • preservation of source ABI alignment at NVVM kernel boundaries.

Packed aggregates containing target-dependent shared-memory pointers should remain fail-closed until their physical representation is target-independent.

This should not change the existing packed field-addressing behavior.

Expected result

For the examples above:

Packed1 -> <{ i8, i32 }>
Packed2 -> <{ i8, [1 x i8], i32 }>

and the generated PTX for Packed2 should retain its Rust ABI alignment:

.param .align 2 .b8 ...[6]

The behavior should be covered by both lowering tests and an end-to-end CUDA kernel launch.

Activity

  1. added
    bug
    codegen
    IR-lowering
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    IR-loweringbugcodegen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions