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

don't emit #[repr(align(0))], and reduced test case #1593

Merged
merged 5 commits into from
Jul 15, 2019

Conversation

pmarks
Copy link
Contributor

@pmarks pmarks commented Jul 14, 2019

fixes #1565
not sure if this is the right fix, but the test case should be useful.

@@ -9,3 +9,7 @@ struct alignas(double) b {
int b;
int c;
};

namespace std {
union a;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, so it's a forward declaration, fun... Let me think a bit whether it's the right fix. Thank you so much for the test-case!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Sorry for the lag, got sidetracked with something else :)

Ok, so this is not the right fix. The right fix is returning None in here if we're a forward declaration (you can check self.is_forward_declaration() right there).

Probably with a comment like:

// By definition, we don't have the right layout information here if
// we're a forward declaration.

Or something of that sort. That should make it behave the same way as opaque forward-declared structs in this case.

It'd be worth adding a different test (not to the repr_align one) testing the behavior here.

The header could be as simple as:

// bindgen-flags: --opaque-type "*"

union a;
struct b;

Would you be able to make those changes? Otherwise I'm happy to do that myself and crediting you appropriately for finding the test-case.

Thanks so much again!

@pmarks
Copy link
Contributor Author

pmarks commented Jul 15, 2019

@emilio thanks for your help! The PR now fixes the original problem, but introduces the following test failure, which unfortunately is way over my head. LMK if you have ideas on how to proceed.

---- header_objc_template_h stdout ----



diff expected generated
--- expected: "/Users/patrick/code/rust-bindgen/tests/expectations/tests/libclang-5/objc_template.rs"
+++ generated from: "/Users/patrick/code/rust-bindgen/tests/headers/objc_template.h"
 /* automatically generated by rust-bindgen */

 #![allow(
     dead_code,
     non_snake_case,
     non_camel_case_types,
     non_upper_case_globals
 )]
 #![cfg(target_os = "macos")]

 #[macro_use]
 extern crate objc;
 #[allow(non_camel_case_types)]
 pub type id = *mut objc::runtime::Object;
 pub trait Foo {
-    unsafe fn get(self) -> *mut ObjectType;
+    unsafe fn get(self) -> u64;
 }
 impl Foo for id {
-    unsafe fn get(self) -> *mut ObjectType {
+    unsafe fn get(self) -> u64 {
         msg_send!(self, get)
     }
 }

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Yeah, those objective-c tests are known-problematic in newer clang versions.

You can skip those changes with git add -p and CI would be happy, sorry for the hassle.

I need to find a bit of time to get all the relevant clang versions we support on CI to run on my machine and spin off another subdirectory with version-specific tests for this. I had been procrastinating on it for a while now :)

Anyhow, just run cargo test with the relevant environment variable, then git add -p everything but the objective-C tests. You can git commit, then git reset --hard HEAD to undo the objective-c changes. Sorry again for the hassle :(

@@ -9,3 +9,4 @@ struct alignas(double) b {
int b;
int c;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove this addition too?

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Oh, and fix looks great now, thanks! r=me with the non objective-c expectations updated :)

@emilio
Copy link
Contributor

emilio commented Jul 15, 2019

And to be clear, that failure should happen with on without your fix, I'm pretty sure.

@pmarks
Copy link
Contributor Author

pmarks commented Jul 15, 2019

@emilio apologies: I didn't recheck the original test case. It's still broken. I'm re-reducing w/ the first fix in place.

@pmarks
Copy link
Contributor Author

pmarks commented Jul 15, 2019

Here's the new test case:

template <int> class a {
  union {};
};

@emilio
Copy link
Contributor

emilio commented Jul 15, 2019

Ok, so this looks good to merge as-is. I'll suggest a fix for the second test-case as well. But TL;DR: it should be in the same function. Empty unions don't have zero alignment, but we're coming up with that in that test-case.

@emilio emilio merged commit 281b62e into rust-lang:master Jul 15, 2019
@pmarks pmarks deleted the pmarks/issue-1565 branch July 20, 2019 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repr(align(0)) for std::basic_string causing build error
3 participants