From fe533e862cd2d2d65e14970d327365dfe593aa27 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 Jun 2022 13:38:35 -0700 Subject: [PATCH] Specify DWARF alignment in bits, not bytes. In DWARF, alignment of types is specified in bits, as is made clear by the parameter name `AlignInBits`. However, `rustc` was incorrectly passing a byte alignment. This commit fixes that. This was noticed in upstream LLVM when I tried to check in a test consisting of LLVM IR generated from `rustc` and it triggered assertions [1]. [1]: https://reviews.llvm.org/D126835 --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 2 +- src/test/codegen/debug-alignment.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/test/codegen/debug-alignment.rs diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index dd3adbf70a62f..f5cbbc7ca9198 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1365,7 +1365,7 @@ pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, glo is_local_to_unit, global, None, - global_align.bytes() as u32, + global_align.bits() as u32, ); } } diff --git a/src/test/codegen/debug-alignment.rs b/src/test/codegen/debug-alignment.rs new file mode 100644 index 0000000000000..f6c1062e0fc6c --- /dev/null +++ b/src/test/codegen/debug-alignment.rs @@ -0,0 +1,8 @@ +// Verifies that DWARF alignment is specified properly. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// CHECK: !DIGlobalVariable +// CHECK: align: 32 +pub static A: u32 = 1;