Skip to content

Commit d1d79ae

Browse files
committed
Auto merge of #55701 - tromey:ice-fix, r=matthewjasper
Fix emission of niche-filling discriminant values Bug #55606 points out a regression introduced by #54004; namely that an assertion can erroneously fire when a niche-filling discriminant value is emitted. This fixes the bug by removing the assertion, and furthermore by arranging for the discriminant value to be masked according to the size of the niche. This makes handling the discriminant a bit simpler for debuggers. The test case is from Jonathan Turner. Closes #55606
2 parents d8f4c9f + 4d20dd4 commit d1d79ae

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12791279
niche_start,
12801280
ref variants,
12811281
dataful_variant,
1282-
..
1282+
ref niche,
12831283
} => {
12841284
if fallback {
12851285
let variant = self.layout.for_variant(cx, dataful_variant);
@@ -1361,11 +1361,11 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13611361
let niche_value = if i == dataful_variant {
13621362
None
13631363
} else {
1364-
let niche = (i as u128)
1364+
let value = (i as u128)
13651365
.wrapping_sub(*niche_variants.start() as u128)
13661366
.wrapping_add(niche_start);
1367-
assert_eq!(niche as u64 as u128, niche);
1368-
Some(niche as u64)
1367+
let value = value & ((1u128 << niche.value.size(cx).bits()) - 1);
1368+
Some(value as u64)
13691369
};
13701370

13711371
MemberDescription {
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test depends on a patch that was committed to upstream LLVM
12+
// before 7.0, then backported to the Rust LLVM fork. It tests that
13+
// optimized enum debug info accurately reflects the enum layout.
14+
15+
// ignore-tidy-linelength
16+
// ignore-windows
17+
// min-system-llvm-version 7.0
18+
19+
// compile-flags: -g -C no-prepopulate-passes
20+
21+
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
22+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i64 4294967295{{[,)].*}}
23+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i64 0{{[,)].*}}
24+
25+
#![feature(never_type)]
26+
#![feature(nll)]
27+
28+
#[derive(Copy, Clone)]
29+
pub struct Entity {
30+
private: std::num::NonZeroU32,
31+
}
32+
33+
#[derive(Copy, Clone, PartialEq, Eq)]
34+
pub struct Declaration;
35+
36+
impl TypeFamily for Declaration {
37+
type Base = Base;
38+
type Placeholder = !;
39+
40+
fn intern_base_data(_: BaseKind<Self>) {}
41+
}
42+
43+
#[derive(Copy, Clone)]
44+
pub struct Base;
45+
46+
pub trait TypeFamily: Copy + 'static {
47+
type Base: Copy;
48+
type Placeholder: Copy;
49+
50+
fn intern_base_data(_: BaseKind<Self>);
51+
}
52+
53+
#[derive(Copy, Clone)]
54+
pub enum BaseKind<F: TypeFamily> {
55+
Named(Entity),
56+
Placeholder(F::Placeholder),
57+
Error,
58+
}
59+
60+
pub fn main() {
61+
let x = BaseKind::Error::<Declaration>;
62+
let y = 7;
63+
}

0 commit comments

Comments
 (0)