Skip to content

Zero-sized functions pointers no longer variadic-compatible #32201

Closed
@alexcrichton

Description

@alexcrichton

Seems like a crazy edge case, but this code works on stable but is currently broken on nightly.

#![crate_type = "lib"]

extern {
    fn foo(a: i32, ...);
}

extern fn bar() {}

pub fn bad() {
    unsafe {
        foo(0, bar);
    }
}

On stable Rust, this produces the IR:

define void @_ZN3bad20h6e7ac30c4401351fnaaE() unnamed_addr #2 {
entry-block:
  tail call void (i32, ...) @foo(i32 3, void ()* nonnull @_ZN3bar20h7198ce9121a8c42ckaaE)
  ret void
}

whereas on nightly it looks like:

define void @_ZN3bad20had7770d3eb571d55naaE() unnamed_addr #1 {
entry-block:
  tail call void (i32, ...) @foo(i32 3, {} undef)
  ret void
}

Which is clearly bad! I noticed there's a warning for transmuting function types to function pointers (as now it's 0-sized to pointer-sized), but perhaps the same warning could be appplied here? Or better could the coercion be automatically applied?

For reference this was discovered in curl-rust which defines variadic functions.

cc @eddyb, @nikomatsakis

Metadata

Metadata

Assignees

Labels

P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions