Skip to content

stage2 llvm: pointer access with excess alignment, causing segfault #13232

@topolarity

Description

@topolarity

Zig Version

0.10.0-dev.4472+a4eb221b9

Steps to Reproduce

Build Zig and save the LLVM IR:

$ /build/zig2 build -p stage3_debug -Dstrip=true -Denable-llvm=true --verbose-llvm-ir 2>llvm_ir.txt

If you examine Autodocs.walkInstruction in the generated LLVM IR, you'll see this:

; Function Attrs: nounwind sspstrong uwtable
define internal fastcc void @Autodoc.walkInstruction(ptr noalias nonnull sret({ %Autodoc.DocData.WalkResult, i16, [14 x i8] }) %0, ptr nonnull align 8 %1, ptr nonnull align 8 %2, ptr nonnull align 8 %3, ptr nonnull readonly align 8 %4, i64 %5, i1 %6) unnamed_addr #0 {
Entry:
  ...
  %891 = alloca %Autodoc.DocData.Type, align 8
  ...
  %2849 = getelementptr inbounds { %Autodoc.DocData.Type.Type__struct_34832, i5, [15 x i8] }, ptr %891, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2849, ptr align 16 %892, i64 592, i1 false)
  ...
}

Zig claims that %2849 has alignment 16, but it actually has alignment 8.

Expected Behavior

Alignment should be consistent between alloca and memcpy.

Actual Behavior

Alignments do not match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions