From da7b6b4b4dcdf9adf25eca12293be029ce9ce24c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 13 Sep 2018 06:51:17 -0600 Subject: [PATCH] Avoid possible integer overflow in niche value computation @eddyb pointed out in review that the niche value computation had a possible integer overflow problem, fixed here as he suggested. --- src/librustc_codegen_llvm/debuginfo/metadata.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 19ada960db3..ba1e3f5960c 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -1361,8 +1361,11 @@ fn compute_field_path<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, let niche_value = if i == dataful_variant { None } else { - Some((i.wrapping_sub(*niche_variants.start()) as u128) - .wrapping_add(niche_start) as u64) + let niche = (i as u128) + .wrapping_sub(*niche_variants.start() as u128) + .wrapping_add(niche_start); + assert_eq!(niche as u64 as u128, niche); + Some(niche as u64) }; MemberDescription { -- GitLab