about summary refs log tree commit diff
diff options
context:
space:
mode:
authorantoyo <antoyo@users.noreply.github.com>2022-03-30 09:55:30 -0400
committerGitHub <noreply@github.com>2022-03-30 09:55:30 -0400
commitf5375644544ca1d24d65aa5eda2ce8215f199835 (patch)
tree0b8002dbcb7a525872a85df4be69f7cb3147e5f5
parent76cf7c2058489be704864d60360b52a48d9dc2f3 (diff)
parent927eea3860330a52b4594bdad1a771499c8aee19 (diff)
downloadrust-f5375644544ca1d24d65aa5eda2ce8215f199835.tar.gz
rust-f5375644544ca1d24d65aa5eda2ce8215f199835.zip
Merge pull request #148 from rust-lang/feature/packed-struct
Feature/packed struct
-rw-r--r--src/type_.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/type_.rs b/src/type_.rs
index 8a17d94da41..d65649ecfa3 100644
--- a/src/type_.rs
+++ b/src/type_.rs
@@ -115,7 +115,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
         self.context.new_function_pointer_type(None, return_type, params, false)
     }
 
-    fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
+    fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
         let types = fields.to_vec();
         if let Some(typ) = self.struct_types.borrow().get(fields) {
             return typ.clone();
@@ -123,8 +123,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
         let fields: Vec<_> = fields.iter().enumerate()
             .map(|(index, field)| self.context.new_field(None, *field, &format!("field{}_TODO", index)))
             .collect();
-        // TODO(antoyo): use packed.
         let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
+        if packed {
+            typ.set_packed();
+        }
         self.struct_types.borrow_mut().insert(types, typ);
         typ
     }
@@ -209,12 +211,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         self.type_array(self.type_from_integer(unit), size / unit_size)
     }
 
-    pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], _packed: bool) {
-        // TODO(antoyo): use packed.
+    pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed: bool) {
         let fields: Vec<_> = fields.iter().enumerate()
             .map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index)))
             .collect();
         typ.set_fields(None, &fields);
+        if packed {
+            typ.as_type().set_packed();
+        }
     }
 
     pub fn type_named_struct(&self, name: &str) -> Struct<'gcc> {