Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When declaring extern fns from external crates, use the correct abi #9196

Merged
merged 1 commit into from
Sep 16, 2013

Conversation

alexcrichton
Copy link
Member

Beforehand it was assumed that the standard cdecl abi was used for all extern
fns of extern crates, but this reads the abi of the extern fn type and declares
the function in the local crate with the appropriate type.

I was trying to think of how to write a test for this, but I was just drawing up blanks :(. Are there standard functions in libc which are not of the cdecl abi? If so we could try linking to them and make sure that the cal completes successfully.

Otherwise, I manually verified that the function was declared correctly by looking at the llvm assembly.

cc #9055 (I'm not sure if this will fix that issue)

ty::ty_bare_fn(_) | ty::ty_closure(_) => {
ty::ty_bare_fn(ref fn_ty) => {
let cconv = foreign::llvm_calling_convention(ccx, fn_ty.abis);
let cconv = cconv.unwrap_or_default(lib::llvm::CCallConv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be .unwrap_or(lib::llvm::CCallConv).

@thestinger
Copy link
Contributor

@alexcrichton: nope - really no way to add a test unless we add something like a syscall ABI and even then you can only have the test for Linux

You could write a Windows-only test with stdcall.... but apparently it's not different enough to be broken already.

Beforehand it was assumed that the standard cdecl abi was used for all extern
fns of extern crates, but this reads the abi of the extern fn type and declares
the function in the local crate with the appropriate type.
bors added a commit that referenced this pull request Sep 16, 2013
Beforehand it was assumed that the standard cdecl abi was used for all extern
fns of extern crates, but this reads the abi of the extern fn type and declares
the function in the local crate with the appropriate type.

I was trying to think of how to write a test for this, but I was just drawing up blanks :(. Are there standard functions in libc which are not of the cdecl abi? If so we could try linking to them and make sure that the cal completes successfully.

Otherwise, I manually verified that the function was declared correctly by looking at the llvm assembly.

cc #9055 (I'm not sure if this will fix that issue)
@bors bors closed this Sep 16, 2013
@bors bors merged commit 297ac73 into rust-lang:master Sep 16, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 18, 2022
Fix example for `clippy::invalid_regex`

Close rust-lang#9194
changelog: previous example doesn't trigger lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants