Skip to content

incorrect LLVM IR generated for align 1 struct pointer dereferenced and returned #25067

Description

@andrewrk
const std = @import("std");

pub const panic = std.debug.no_panic;

export fn ok() bool {
    var buffer: [5]u8 align(4) = .{ 1, 2, 3, 4, 5 };
    const s = gimme(@ptrCast(buffer[1..]));
    return s.a == 0x02030405;
}

const S = extern struct {
    a: u32,
};

fn gimme(p: *align(1) S) S {
    return p.*;
}

Generates this LLVM IR:

; Function Attrs: noredzone nounwind uwtable
define internal fastcc void @test.gimme(ptr noalias sret(%test.S) nonnull %0, ptr align 1 nonnull %1) unnamed_addr #0 {
2:
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %1, i64 4, i1 false)
  ret void
}

Bad alignment on the memcpy.

Activity

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

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions