Skip to content

ir: Handle properly template alias instantiations in clang >3.9 #696

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

Merged
merged 1 commit into from
May 10, 2017

Conversation

emilio
Copy link
Contributor

@emilio emilio commented May 10, 2017

No description provided.

@emilio emilio force-pushed the template-alias-inst branch from d01e10e to 827254b Compare May 10, 2017 12:51
@emilio emilio changed the title ir: Handle properly template instantiation specializations in clang >3.9 ir: Handle properly template alias instantiations in clang >3.9 May 10, 2017
@emilio
Copy link
Contributor Author

emilio commented May 10, 2017

r? @fitzgen

@emilio
Copy link
Contributor Author

emilio commented May 10, 2017

With this and #694, the following is the test difference:

diff --git a/tests/expectations/tests/objc_template.rs b/tests/expectations/tests/objc_template.rs
index e5a874c6..95d12ff6 100644
--- a/tests/expectations/tests/objc_template.rs
+++ b/tests/expectations/tests/objc_template.rs
@@ -11,8 +11,8 @@ extern crate objc;
 pub type id = *mut objc::runtime::Object;
 pub trait Foo {
     unsafe fn get(self)
-    -> id;
+    -> *mut ObjectType;
 }
 impl Foo for id {
-    unsafe fn get(self) -> id { msg_send!(self , get) }
+    unsafe fn get(self) -> *mut ObjectType { msg_send!(self , get) }
 }
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index d4f81711..00061ecd 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -256,7 +256,18 @@ fn __bindgen_test_layout_Foo_instantiation_95() {
                Foo<::std::os::raw::c_int> ) ));
 }
 #[test]
-fn __bindgen_test_layout_Rooted_instantiation_106() {
+fn __bindgen_test_layout_Foo_instantiation_101() {
+    assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize ,
+               concat ! (
+               "Size of template specialization: " , stringify ! (
+               Foo<::std::os::raw::c_int> ) ));
+    assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int>>() , 8usize ,
+               concat ! (
+               "Alignment of template specialization: " , stringify ! (
+               Foo<::std::os::raw::c_int> ) ));
+}
+#[test]
+fn __bindgen_test_layout_Rooted_instantiation_111() {
     assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() ,
                24usize , concat ! (
                "Size of template specialization: " , stringify ! (
@@ -267,7 +278,7 @@ fn __bindgen_test_layout_Rooted_instantiation_106() {
                Rooted<*mut ::std::os::raw::c_void> ) ));
 }
 #[test]
-fn __bindgen_test_layout_WithDtor_instantiation_114() {
+fn __bindgen_test_layout_WithDtor_instantiation_123() {
     assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
                4usize , concat ! (
                "Size of template specialization: " , stringify ! (
diff --git a/tests/expectations/tests/type_alias_template_specialized.rs b/tests/expectations/tests/type_alias_template_specialized.rs
index 20665af6..feb2a45e 100644
--- a/tests/expectations/tests/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/type_alias_template_specialized.rs
@@ -5,9 +5,9 @@
 
 
 #[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Copy)]
 pub struct Rooted {
-    pub ptr: ::std::os::raw::c_int,
+    pub ptr: MaybeWrapped<::std::os::raw::c_int>,
 }
 #[test]
 fn bindgen_test_layout_Rooted() {
@@ -24,5 +24,8 @@ fn bindgen_test_layout_Rooted() {
 impl Clone for Rooted {
     fn clone(&self) -> Self { *self }
 }
+impl Default for Rooted {
+    fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
 /// <div rustbindgen replaces="MaybeWrapped"></div>
 pub type MaybeWrapped<a> = a;

@emilio
Copy link
Contributor Author

emilio commented May 10, 2017

One of those is #695, the other changes are more correct AFAIK.

This fixes tests/expectations/tests/type_alias_template_specialized.rs in those
clang versions (without regressions, hopefully), and makes the behavior the
proper one, without needing replacements.
@emilio emilio force-pushed the template-alias-inst branch from f31a88c to b2e5613 Compare May 10, 2017 13:45
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Awesome! THanks!

@fitzgen
Copy link
Member

fitzgen commented May 10, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit b2e5613 has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit b2e5613 with merge d4f83a9...

bors-servo pushed a commit that referenced this pull request May 10, 2017
ir: Handle properly template alias instantiations in clang >3.9
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing d4f83a9 to master...

@bors-servo bors-servo merged commit b2e5613 into rust-lang:master May 10, 2017
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