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

[Windows] Wrong ABI when interfacing with C code #28676

Closed
tomaka opened this issue Sep 26, 2015 · 3 comments
Closed

[Windows] Wrong ABI when interfacing with C code #28676

tomaka opened this issue Sep 26, 2015 · 3 comments
Labels
O-windows Operating system: Windows

Comments

@tomaka
Copy link
Contributor

tomaka commented Sep 26, 2015

Here is a gist containing the entire source code if you want to reproduce.

When calling the function foo defined like this in C:

typedef struct {
    size_t a;
    size_t b;
    size_t c;
    size_t d;
} Foo;

size_t foo(void* a, void* b, void* c, void* d, Foo f) {
    return f.c;
}

And like this in Rust:

extern {
    fn foo(_: *const libc::c_void, _: *const libc::c_void, _: *const libc::c_void,
           _: *const libc::c_void, _: Foo) -> libc::size_t;
}

You get a crash with the MSVC version of Rust, but the MinGW version works.

This is because apparently the C code expects Foo to actually be a pointer.

If you change the Rust declaration to *const Foo, then it works with the MSVC version and crashes with the MinGW version.

@tomaka
Copy link
Contributor Author

tomaka commented Sep 26, 2015

Someone pointed out that this is maybe not a MSVC-related issue.
I only tested 32 MinGW vs 64 bits MSVC, so maybe it's an issue of 32bits vs 64bits instead of MinGW vs MSVC.

@tomaka tomaka changed the title [MSVC] Wrong ABI when interfacing with C code [Windows] Wrong ABI when interfacing with C code Sep 26, 2015
@retep998
Copy link
Member

Possibly related to #24427

@eefriedman
Copy link
Contributor

_ => ArgType::indirect(t, Some(Attribute::ByVal))
should probably be ArgType::indirect(t, None). The equivalent clang code: https://github.com/llvm-mirror/clang/blob/69b5694b76d36fde04c1f3511459a575e48f201d/lib/CodeGen/TargetInfo.cpp#L3338 .

@steveklabnik steveklabnik added the O-windows Operating system: Windows label Sep 28, 2015
tari added a commit to tari/rust that referenced this issue Oct 14, 2015
bors added a commit that referenced this issue Oct 15, 2015
Fixes #28676.

There doesn't seem to be a good way to add a test for this, but I tested the repro in #28676 and confirmed it now yields the correct result.
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 17, 2021
…enkov

Move some tests to more reasonable directories - 2

All tests with a score equal or greater than 1.0 were moved to their respective directories by issuing

```bash
cat FILE | tr -s " " | tr -d '():' | sort -k3 | awk '$3 >= 1' | cut -d " " -f1-2 | sed 's;\\;/;g' | xargs -n2 git mv
```
**Observation**: The first column values is the only column with results greater zero

To attest the confidentiality of the model, some manual revision of at least of tests is needed and this process will be tracked in the following list:

* `src/test/ui/abi/issue-28676.rs` OK rust-lang#28676
* `src/test/ui/array-slice-vec/issue-15730.rs` OK
* `src/test/ui/associated-types/issue-24338.rs` OK rust-lang#54823
* `src/test/ui/associated-types/issue-48551.rs` Looks OK rust-lang#48551
* `src/test/ui/associated-types/issue-50301.rs` Looks OK rust-lang#63577

...

cc rust-lang#73494
r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

4 participants