Skip to content

Add missing attributes to indirect calls for foreign functions #14982

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

Closed
wants to merge 1 commit into from

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Jun 17, 2014

When calling a foreign function, some arguments and/or return value
attributes are required to conform to the foreign ABI. Currently those
attributes are only added to the declaration of foreign functions. With
direct calls, this is no problem, because LLVM can see that those
attributes apply to the call. But with an indirect call, LLVM cannot do
that and the attribute is missing.

To fix that, we have to add those attribute to the calls to foreign
functions as well.

@alexcrichton
Copy link
Member

Instead of adding a run-make test, could you add a run-pass test by modifying src/rt/rust_builtin.c and linking to the rust_test_helpers library?

let mut attrs = Vec::new();
if fn_type.ret_ty.is_indirect() {
attrs.push((1, lib::llvm::StructRetAttribute as u64));
Copy link
Member

Choose a reason for hiding this comment

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

Was this accidentally removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that's on purpose. StructRetAttribute is handled via the attr field of the ArgType.

Edit: The code to set attr to StructRetAttribute was already present and the value is used in add_argument_attributes. We just completely ignored attr here and the hard-coded attribute here had to make up for it.

@dotdash
Copy link
Contributor Author

dotdash commented Jun 17, 2014

Shoudl I really modify rust_builtin.c? Seems like that would "revive" #2665 (btw. I guess the FIXME can be removed from rust_test_helpers.c now as #14677 has landed?)

@alexcrichton
Copy link
Member

Oh sorry! I meant to modify rust_test_helpers.c!

@alexcrichton
Copy link
Member

As in, I meant to recommend you modify rust_test_helpers.c

When calling a foreign function, some arguments and/or return value
attributes are required to conform to the foreign ABI. Currently those
attributes are only added to the declaration of foreign functions. With
direct calls, this is no problem, because LLVM can see that those
attributes apply to the call. But with an indirect call, LLVM cannot do
that and the attribute is missing.

To fix that, we have to add those attribute to the calls to foreign
functions as well.

This also allows to remove the special handling of the SRet attribute,
which is ABI-dependent and will be set via the `attr` field of the
return type's `ArgType`.
@dotdash
Copy link
Contributor Author

dotdash commented Jun 18, 2014

Obsoleted by #15005

@dotdash dotdash closed this Jun 18, 2014
@dotdash dotdash deleted the foreign_abi_attr branch February 4, 2015 12:46
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.

2 participants