Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

let init = crate::consts::const_alloc_to_gcc_uncached(self, alloc);
let alloc = alloc.inner();
let typ = self.val_ty(init).get_aligned(alloc.align.bytes());

let mut typ = self.val_ty(init);
// FIXME(GuillaumeGomez): is it only structs or could be other types?
if typ.is_struct().is_some() {
typ = typ.get_aligned(alloc.align.bytes());
}

let global = self.declare_global_with_linkage(&name, typ, GlobalKind::Internal);

Expand Down
16 changes: 11 additions & 5 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,19 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
Some(kind) if !self.tcx.sess.fewer_names() => {
let name = self.generate_local_symbol_name(kind);
// FIXME(antoyo): check if it's okay that no link_section is set.

let typ = self.val_ty(cv).get_aligned(align.bytes());
let mut typ = self.val_ty(cv);
// FIXME(GuillaumeGomez): is it only structs or could be other types?
if typ.is_struct().is_some() {
typ = typ.get_aligned(align.bytes());
}
self.declare_private_global(&name[..], typ)
}
_ => {
let typ = self.val_ty(cv).get_aligned(align.bytes());
let mut typ = self.val_ty(cv);
// FIXME(GuillaumeGomez): is it only structs or could be other types?
if typ.is_struct().is_some() {
typ = typ.get_aligned(align.bytes());
}
self.declare_unnamed_global(typ)
}
};
Expand Down Expand Up @@ -397,8 +404,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
llvals.push(cx.const_bytes(bytes));
}

// FIXME(bjorn3) avoid wrapping in a struct when there is only a single element.
cx.const_struct(&llvals, true)
if let &[data] = &*llvals { data } else { cx.const_struct(&llvals, true) }
}

fn codegen_static_initializer<'gcc, 'tcx>(
Expand Down
Loading