Skip to content

FFI calls may create out-of-bounds loads #29988

Closed
@dotdash

Description

@dotdash

Given this Rust code:

#[repr(C)]
struct S {
    f1: i32,
    f2: i32,
    f3: i32,
}

extern {
    fn foo(s: S);
}

A call to foo() generates IR like this on x86_64 Linux:

  %S = type { i32, i32, i32 }
; ...
  %arg = alloca %S
; ...
  %2 = bitcast %S* %s to i8*
  %3 = bitcast %S* %arg to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %3, i8* %2, i64 12, i32 4, i1 false)
  %4 = bitcast %S* %arg to { i64, i64 }*
  %5 = load { i64, i64 }, { i64, i64 }* %4
  call void @x({ i64, i64 } %5)

So we have a 12 byte alloca from which we then read 16 bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions