Skip to content

Commit 3ab275b

Browse files
authored
Unrolled build for #144407
Rollup merge of #144407 - godzie44:godzie44/fix_dwarf_inconsistency, r=wesleywiser fix(debuginfo): disable overflow check for recursive non-enum types Commit b10edb4 introduce an overflow check when generating debuginfo for expanding recursive types. While this check works correctly for enums, it can incorrectly prune valid debug information for structures. For example see #143241 (#143241 (comment)). Furthermore, for structures such check does not make sense, since structures with recursively expanding types simply will not compile (there is a `hir_analysis_recursive_generic_parameter` for that). closes #143241
2 parents 5529041 + 49eda8e commit 3ab275b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
285285
// Item(T),
286286
// }
287287
// ```
288-
let is_expanding_recursive =
289-
debug_context(cx).adt_stack.borrow().iter().any(|(parent_def_id, parent_args)| {
288+
let is_expanding_recursive = adt_def.is_enum()
289+
&& debug_context(cx).adt_stack.borrow().iter().any(|(parent_def_id, parent_args)| {
290290
if def_id == *parent_def_id {
291291
args.iter().zip(parent_args.iter()).any(|(arg, parent_arg)| {
292292
if let (Some(arg), Some(parent_arg)) = (arg.as_type(), parent_arg.as_type())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@ compile-flags:-g -Copt-level=0 -C panic=abort
2+
3+
// Check that debug information exists for structures containing loops (cyclic references).
4+
// Previously it may incorrectly prune member information during recursive type inference check.
5+
6+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Arc<debuginfo_cyclic_structure::Inner<alloc::sync::Arc<debuginfo_cyclic_structure::Handle{{.*}}elements: ![[FIELDS:[0-9]+]]
7+
// CHECK: ![[FIELDS]] = !{!{{.*}}}
8+
// CHECK-NOT: ![[FIELDS]] = !{}
9+
10+
#![crate_type = "lib"]
11+
12+
use std::mem::MaybeUninit;
13+
use std::sync::Arc;
14+
15+
struct Inner<T> {
16+
buffer: Box<MaybeUninit<T>>,
17+
}
18+
struct Shared {
19+
shared: Arc<Inner<Arc<Handle>>>,
20+
}
21+
struct Handle {
22+
shared: Shared,
23+
}
24+
struct Core {
25+
inner: Arc<Inner<Arc<Handle>>>,
26+
}
27+
28+
#[no_mangle]
29+
extern "C" fn test() {
30+
let с = Core { inner: Arc::new(Inner { buffer: Box::new(MaybeUninit::uninit()) }) };
31+
std::hint::black_box(с);
32+
}

0 commit comments

Comments
 (0)